萌新求助WA on #4
查看原帖
萌新求助WA on #4
374756
忘怜城羡楼主2024/5/15 16:32

rt

#include<bits/stdc++.h>
using namespace std;
const int MAXN=3e5+7,T=1e6+7;
struct paint{
	int x,l,r;
	bool operator < (const paint &xx) const{
		if(x!=xx.x)
			return x<xx.x;
		else
			return l<xx.l;
	}
}a[MAXN];
struct node{
	int maxe,lazytag,ls,rs,s;
	bool operator < (const node &x) const{
		return maxe<x.maxe;
	}
}tree[T<<2];
set<int> s;
unordered_map<int,int> mp;
int cnt,root,tot,dp[MAXN],g[MAXN],ans;
bool vis[MAXN];
void pushup(int p)
{
	if(tree[tree[p].ls].maxe>=tree[tree[p].rs].maxe)
	{
		tree[p].maxe=tree[tree[p].ls].maxe;
		tree[p].s=tree[tree[p].ls].s;
	}
	else
	{
		tree[p].maxe=tree[tree[p].rs].maxe;
		tree[p].s=tree[tree[p].rs].s;
	}
}
void pushdown(int p)
{
	if(!tree[p].ls)
		tree[p].ls=++tot;
	if(!tree[p].rs)
		tree[p].rs=++tot;
	tree[tree[p].ls].maxe=tree[tree[p].rs].maxe=tree[p].lazytag;
	tree[tree[p].ls].lazytag=tree[tree[p].rs].lazytag=tree[p].lazytag;
	tree[tree[p].ls].s=tree[tree[p].rs].s=tree[p].s;
	tree[p].lazytag=0;
	return ;
}
node query(int p,int l,int r,int x,int y)
{
	if(!p||x>y)
		return node{0,0,0,0,0};
	if(x<=l&&r<=y)
		return tree[p];
	if(tree[p].lazytag)
		pushdown(p);
	int mid=(l+r)>>1;
	node sum;
	sum={0,0,0,0,0};
	if(x<=mid)
		sum=max(sum,query(tree[p].ls,l,mid,x,y));
	if(mid<y)
		sum=max(sum,query(tree[p].rs,mid+1,r,x,y));
	return sum;
}
void modify(int &p,int l,int r,int x,int y,int v,int w)
{
	if(!p)
		p=++tot;
	if(x<=l&&r<=y)
	{
		if(tree[p].maxe<v)
		{
			tree[p].maxe=v;
			tree[p].lazytag=v;
			tree[p].s=w;
		}
		return ;
	}
	int mid=(l+r)>>1;
	if(tree[p].lazytag)
		pushdown(p);
	if(x<=mid)
		modify(tree[p].ls,l,mid,x,y,v,w);
	if(mid<y)
		modify(tree[p].rs,mid+1,r,x,y,v,w);
	pushup(p);
	return ;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	memset(g,0,sizeof(g));
	dp[1]=1;
	for(int i(1);i<=m;++i)
	{
		scanf("%d%d%d",&a[i].x,&a[i].l,&a[i].r);
		s.insert(a[i].l);
		s.insert(a[i].r);
	}
	sort(a+1,a+m+1);
	for(set<int>::iterator it=s.begin();it!=s.end();++it)
		mp[*it]=++cnt;
	for(int i(1);i<=m;++i)
	{
		a[i].l=mp[a[i].l];
		a[i].r=mp[a[i].r];
	}
	int k=1;
	for(int i(1);i<=m;++i)
	{
		if(a[i].x!=1)
			break;
		modify(root,1,T,a[i].l,a[i].r,1,1);
		k=i+1;
	}
	for(int i(2);i<=n;++i)
	{
		int l=k,r=k,pre=0;
		while(a[l].x<i&&l<=m)
			r=++l;
		while(a[r].x==i&&r<=m)
			++r;
		r--;
		int maxl=0;
		for(int j(l);j<=r;++j)
		{
			node tmp=query(root,1,T,max(a[j].l,maxl),a[j].r);
			if(tmp.maxe+1>dp[i])
			{
				dp[i]=tmp.maxe+1;
				pre=tmp.s;
			}
			maxl=max(maxl,a[j].r+1);
		}
		for(int j(l);j<=r;++j)
			modify(root,1,T,a[j].l,a[j].r,dp[i],i);
		k=r+1;
		g[i]=pre;
	}
	int maxi=0;
	for(int i(1);i<=n;++i)
		if(dp[i]>ans)
		{
			ans=dp[i];
			maxi=i;
		}
	printf("%d\n",n-ans);
	while(maxi!=0)
	{
		vis[maxi]=1;
		maxi=g[maxi];
	}
	for(int i(1);i<=n;++i)
		if(!vis[i])
			printf("%d ",i);
	return 0;
}
2024/5/15 16:32
加载中...