QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#240995#964. Excluded MinThankto_zy6WA 3ms9820kbC++143.4kb2023-11-05 21:43:362023-11-05 21:43:37

Judging History

你现在查看的是最新测评结果

  • [2023-11-05 21:43:37]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9820kb
  • [2023-11-05 21:43:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int a[200005];
int l[200005],r[200005];
int ans[200005];
const int INF=1<<28;
const int N=200000;
struct point{
	int x[2];
	int id;
	bool operator == (point y)const{
		return y.x[0]==x[0]&&y.x[1]==x[1];
	}
}p[200005],g[200005];
bool cmp1(point x,point y)
{
	return x.x[0]<y.x[0]||x.x[0]==y.x[0]&&x.x[1]<y.x[1];
}
bool cmp2(point x,point y)
{
	return x.x[1]<y.x[1]||x.x[1]==y.x[1]&&x.x[0]<y.x[0];
}
int _x;
namespace edge{
	int he[200005],to[200005],ne[200005],cnt;
	void link(int x,int y)
	{
		cnt++;
		to[cnt]=y;
		ne[cnt]=he[x];
		he[x]=cnt;
	}
}
namespace star{
	int he[200005],to[200005],ne[200005],cnt;
	void link(int x,int y)
	{
		cnt++;
		to[cnt]=y;
		ne[cnt]=he[x];
		he[x]=cnt;
	}
}
namespace KDT{
	struct node{
		int fl;
		int lx,rx,ly,ry,dep;
		int mx,tag;
		int ls,rs;
		void make(int _l,int _r,int _s,int _t,int _d){lx=_l;rx=_r;ly=_s;ry=_t;dep=_d;}
	}tr[2000005];
	void add_tag(int k,int val)
	{
		tr[k].mx+=val;
		tr[k].tag+=val;
	}
	void pushdown(int k)
	{
		if(tr[k].ls)add_tag(tr[k].ls,tr[k].tag);
		if(tr[k].rs)add_tag(tr[k].rs,tr[k].tag);
		tr[k].tag=0;
	}
	void pushup(int k)
	{
		tr[k].mx=max(tr[tr[k].ls].mx,tr[tr[k].rs].mx);
	}
	int tot;
	int build(int l,int r,int d)
	{
		int mid=(l+r)>>1,no=++tot;
		tr[no].dep=d;
		tr[no].fl=-1;
		if(l==r)
		{
			tr[no].make(p[l].x[0],p[l].x[0],p[l].x[1],p[l].x[1],d);
			tr[no].fl=l;
			return no;
		}
		if(d&1)
		{
			nth_element(p+l,p+mid,p+r+1,cmp1);
			tr[no].ls=build(l,mid,d+1);
			tr[no].rs=build(mid+1,r,d+1);
		}
		else
		{
			nth_element(p+l,p+mid,p+r+1,cmp2);
			tr[no].ls=build(l,mid,d+1);
			tr[no].rs=build(mid+1,r,d+1);
		}
		tr[no].lx=min(tr[tr[no].ls].lx,tr[tr[no].rs].lx);
		tr[no].rx=max(tr[tr[no].ls].rx,tr[tr[no].rs].rx);
		tr[no].ly=min(tr[tr[no].ls].ly,tr[tr[no].rs].ly);
		tr[no].ry=max(tr[tr[no].ls].ry,tr[tr[no].rs].ry);
		pushup(no);
		return no;
	}
	bool outof(int a,int b,int c,int d)
	{
		return (b<c)||(a>d);
	}
	void modify(int k,int lx,int rx,int ly,int ry,int v)
	{
		if(outof(tr[k].lx,tr[k].rx,lx,rx)||outof(tr[k].ly,tr[k].ry,ly,ry))return;
		if(lx<=tr[k].lx&&tr[k].rx<=rx&&ly<=tr[k].ly&&tr[k].ry<=ry)
		{
			add_tag(k,v);
			return;
		}
		pushdown(k);
		if(tr[k].ls)modify(tr[k].ls,lx,rx,ly,ry,v);
		if(tr[k].rs)modify(tr[k].rs,lx,rx,ly,ry,v);
		pushup(k);
	}
	bool search(int k)
	{
		if(tr[k].fl!=-1)
		{
			if(tr[k].mx>=_x)
			{
				for(int i=star::he[tr[k].fl];i;i=star::ne[i])
				{
					ans[star::to[i]]=_x;
				}
				tr[k].mx=-INF;
				return true;
			}
			return false;
		}
		pushdown(k);
		bool ret;
		if(tr[tr[k].ls].mx>=tr[tr[k].rs].mx)
		{
			ret=search(tr[k].ls);
		}
		else
		{
			ret=search(tr[k].rs);
		}
		pushup(k);
		return ret;
	}
}
int main()
{
	int n,m,q=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		edge::link(a[i],i);
	}
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&l[i],&r[i]);
		g[i]={{l[i],r[i]},i};
	}
	sort(g+1,g+1+m,cmp1);
	for(int i=1;i<=m;i++)
	{
		if(!(g[i]==g[i-1]))
		{
			q++;
			p[q]={{l[i],r[i]},q};
		}
		star::link(q,i);
	}
	int rt=KDT::build(1,q,1);
	for(int i=1;i<=n;i++)KDT::modify(rt,1,i,i,n,1);
	_x=N+1;
	while(_x>=0)
	{
		for(int i=edge::he[_x];i;i=edge::ne[i])
		{
			int j=edge::to[i];
			KDT::modify(rt,1,j,j,n,-1);
		}
		while(KDT::search(rt));
		_x--;
	}
	for(int i=1;i<=m;i++)
	{
		printf("%d\n",ans[i]);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 7716kb

input:

3 3
0 0 2
1 3
2 3
3 3

output:

3
1
0

result:

ok 3 number(s): "3 1 0"

Test #2:

score: 0
Accepted
time: 2ms
memory: 9760kb

input:

3 2
1 2 2
1 2
1 3

output:

0
3

result:

ok 2 number(s): "0 3"

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 9820kb

input:

10 10
3 0 3 3 9 7 9 6 0 7
3 3
9 9
4 6
1 9
3 4
2 4
7 10
3 7
5 7
2 7

output:

0
1
0
5
1
0
0
0
1
1

result:

wrong answer 5th numbers differ - expected: '0', found: '1'