QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#50819#964. Excluded MinCrysflyWA 11ms47740kbC++113.1kb2022-09-29 15:08:092022-09-29 15:08:10

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-29 15:08:10]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:47740kb
  • [2022-09-29 15:08:09]
  • 提交

answer

// what is matter? never mind.
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 500005
#define inf 0x3f3f3f3f

int n,m,a[maxn],res[maxn],mx;
struct qry{
	int l,r,id;
	bool operator <(const qry&b)const{return l<b.l||(l==b.l&&r>b.r);}
}q[maxn];

struct bit{
	int tr[maxn];
	void U(int x,int y){for(;x<=n;x+=x&-x)tr[x]+=y;}
	int Q(int x){int s=0;for(;x;x^=x&-x)s+=tr[x];return s;}
	int Q(int l,int r){return Q(r)-Q(l-1);}
}tr;

struct segt{
	pii t[maxn<<2]; int tag[maxn<<2];
	void build(int p,int l,int r,bool bo){
		t[p]=mkp(-inf,bo?r:-l);
		if(l==r)return;
		int mid=l+r>>1;
		build(p<<1,l,mid,bo),build(p<<1|1,mid+1,r,bo); 
	}
	void up(int p){t[p]=max(t[p<<1],t[p<<1|1]);}
	void pt(int p,int v){tag[p]+=v,t[p].fi+=v;}
	void down(int p){if(tag[p])pt(p<<1,tag[p]),pt(p<<1|1,tag[p]),tag[p]=0;}
	void add(int p,int l,int r,int nl,int nr,int v){
		if(l>=nl&&r<=nr)return pt(p,v);
		int mid=l+r>>1;down(p);
		if(nl<=mid)add(p<<1,l,mid,nl,nr,v);
		if(nr>mid)add(p<<1|1,mid+1,r,nl,nr,v);up(p);
	}
	void upd(int p,int l,int r,int x,pii y){
		if(l==r)return tag[p]=0,t[p]=y,void();
		int mid=l+r>>1;down(p);
		x<=mid?upd(p<<1,l,mid,x,y):upd(p<<1|1,mid+1,r,x,y);up(p);
	}
	pii ask(int p,int l,int r,int ql,int qr){
		if(l>=ql&&r<=qr)return t[p];
		int mid=l+r>>1;down(p);pii res=mkp(-inf,-inf);
		if(ql<=mid)res=max(res,ask(p<<1,l,mid,ql,qr));
		if(qr>mid)res=max(res,ask(p<<1|1,mid+1,r,ql,qr));return res; 
	}
}T,T2;
set<pii>sl,sr;

void push(int i){
	sl.insert(mkp(q[i].l,i)),sr.insert(mkp(q[i].r,i));
	T.upd(1,1,m,i,mkp(tr.Q(q[i].l,q[i].r),i)); 
}
void del(int i){
	T.upd(1,1,m,i,mkp(-inf,i));
	sl.erase(mkp(q[i].l,i));
	auto it=sl.lower_bound(mkp(q[i].l,i));
	int r=(it==sl.end()?m:it->se);
	sr.erase(mkp(q[i].r,i));
	it=sr.lower_bound(mkp(q[i].r,i));
	int tmp=(it==sr.begin()?0:(--it)->fi);
	while(1){
		pii t=T2.ask(1,1,m,i,r);
		if(t.fi<=tmp)return;
		int u=-t.se;
		push(u);
		T2.upd(1,1,m,u,mkp(-1e9,-u));
		r=u;
	}
}
vi vec[maxn];

void dele(int u){
	tr.U(u,-1);
	if(!sl.size())return;
	auto it=sr.lower_bound(mkp(u,0)),it2=sl.lower_bound(mkp(u,inf));
	if(it!=sr.end() && it2!=sl.begin())
		--it2,T.add(1,1,m,it->se,it2->se,-1);
}

signed main()
{
	n=read(),m=read();
	For(i,1,n)a[i]=read(),vec[a[i]].pb(i),mx=max(mx,a[i]),tr.U(i,1);
	For(i,1,m)q[i].l=read(),q[i].r=read(),q[i].id=i;
	sort(q+1,q+m+1);
	T.build(1,1,m,1),T2.build(1,1,m,0);
	int R=0;
	For(i,1,m){
		if(q[i].r>R)push(i),R=q[i].r;
		else T2.upd(1,1,m,i,mkp(q[i].r,-i));
	}
	Rep(i,mx+1,0){
		for(int u:vec[i]) dele(u);
		while(T.t[1].fi>=i){
			int u=T.t[1].se;
			del(u),res[q[u].id]=i;
		}
	}
	For(i,1,m)printf("%d\n",res[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 47740kb

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: 9ms
memory: 47468kb

input:

3 2
1 2 2
1 2
1 3

output:

0
3

result:

ok 2 number(s): "0 3"

Test #3:

score: 0
Accepted
time: 10ms
memory: 47648kb

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
0
1
1
0
0
1

result:

ok 10 numbers

Test #4:

score: -100
Wrong Answer
time: 11ms
memory: 47432kb

input:

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

output:

1
0
2
6
1
4
0
2
6
3

result:

wrong answer 4th numbers differ - expected: '7', found: '6'