$虽然数据有点搞,但是终于AC了2333$
离散化+简单DP+线段树
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef pair<int,int>PII;
const int N=6e5+7;
int n,m;
vector<PII>v[N];
bool vis[N<<1];
struct node
{
int l,r;
PII val;
PII lazy;
}tr[N<<2];
void pushup(int u)
{
tr[u].val=max(tr[u<<1].val,tr[u<<1|1].val);
}
void pushdown(int u)
{
if(tr[u].lazy.y==-1)return ;
auto &root=tr[u],&left=tr[u<<1],&right=tr[u<<1|1];
left.lazy =max(root.lazy, left.lazy), left.val =max(left.val,root.lazy);
right.lazy=max(root.lazy,right.lazy),right.val=max(right.val,root.lazy);
root.lazy={0,-1};
}
void build(int u,int l,int r)
{
if(l==r)tr[u]={l,r,{0,-1},{0,-1}};
else
{
tr[u]={l,r};
int mid=l+r>>1;
build(u<<1,l,mid),build(u<<1|1,mid+1,r);
pushup(u);
}
}
void modify(int u,int l,int r,PII d)
{
if(tr[u].l>=l&&tr[u].r<=r)
tr[u].lazy=max(tr[u].lazy,d),tr[u].val=max(tr[u].val,d);
else
{
pushdown(u);
int mid=tr[u].l+tr[u].r>>1;
if(l<=mid)modify(u<<1,l,r,d);
if(r>mid)modify(u<<1|1,l,r,d);
pushup(u);
}
}
PII query(int u,int l,int r)
{
if(tr[u].l>=l&&tr[u].r<=r)return tr[u].val;
pushdown(u);
PII res={0,-1};
int mid=tr[u].l+tr[u].r>>1;
if(l<=mid)res=max(query(u<<1,l,r),res);
if(r>mid)res=max(query(u<<1|1,l,r),res);
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
cin>>n>>m;
vector<int>nums;
while(m--)
{
int x,l,r;
cin>>x>>l>>r;
v[x].push_back({l,r});
nums.push_back(l),nums.push_back(r);
}
//离散化
sort(nums.begin(),nums.end());
nums.erase(unique(nums.begin(),nums.end()),nums.end());
int sizes=nums.size();
for (int i = 1; i <= n; i++)
for (auto& it : v[i]) {
it.x = upper_bound(nums.begin(),nums.end(), it.x) - nums.begin();
it.y = upper_bound(nums.begin(),nums.end(), it.y) - nums.begin();
}
build(1,1,sizes);
//记录前驱
vector<int>pre(n+1,-1);
//DP
for(int i=1;i<=n;i++)
{
PII mx={0,-1};
for(auto &it:v[i])
mx=max(mx,query(1,it.x,it.y));
pre[i]=mx.y;
mx.x++;
mx.y=i;
for(auto &it:v[i])
modify(1,it.x,it.y,mx);
}
//求最大值
PII ans=query(1,1,sizes);
int cur=ans.y;
while(cur!=-1)
{
vis[cur]=true;
cur=pre[cur];
}
cout<<n-ans.x<<endl;
for(int i=1;i<=n;i++)
if(!vis[i])
cout<<i<<' ';
}
orz
tql