QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#87815#964. Excluded MineyiigjknRE 3ms3836kbC++143.7kb2023-03-14 13:40:122023-03-14 13:40:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-14 13:40:14]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:3836kb
  • [2023-03-14 13:40:12]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
int n,m,ans[500010];
pii a[500010];
struct Query
{
	int l,r,id;
	bool operator<(const Query &t)const{return l!=t.l?l<t.l:r>t.r;}
}qry[500010];
struct Node
{
	int x,id;
	Node(int x,int i):x(x),id(i){}
	bool operator<(const Node &t)const{return x<t.x;}
};
set<Node> sL,sR;
namespace BIT
{
	int sum[500010];
	void update(int x,int y){for(int i=x;i<=n;i+=i&-i) sum[i]+=y;}
	int query(int x)
	{
		int ans=0;
		for(int i=x;i;i-=i&-i) ans+=sum[i];
		return ans;
	}
	inline int query(int l,int r){return query(r)-query(l-1);}
}
namespace S1
{
	int maxn[1100000];
	int getmax(int x,int y)
	{
		if(!x || !y) return x+y;
		else return (qry[x].r!=qry[y].r?qry[x].r>qry[y].r:qry[x].l<qry[y].l)?x:y;
	}
	void pushup(int rt){maxn[rt]=getmax(maxn[rt*2],maxn[rt*2+1]);}
	void build(int rt,int l,int r)
	{
		if(l==r) return void(maxn[rt]=l);
		int mid=(l+r)/2;
		build(rt*2,l,mid);
		build(rt*2+1,mid+1,r);
		pushup(rt);
	}
	void update(int rt,int l,int r,int x)
	{
		if(l==r) return void(maxn[rt]=0);
		int mid=(l+r)/2;
		if(x<=mid) update(rt*2,l,mid,x);
		else update(rt*2+1,mid+1,r,x);
		pushup(rt);
	}
	int query(int rt,int l,int r,int x,int y)
	{
		if(l>y || r<x) return 0;
		if(l>=x && r<=y) return maxn[rt];
		int mid=(l+r)/2;
		return getmax(query(rt*2,l,mid,x,y),query(rt*2+1,mid+1,r,x,y));
	}
}
namespace S2
{
	int addmk[1100000];
	pii maxn[1100000];
	void pushtag(int rt,int x){maxn[rt].first+=x;addmk[rt]+=x;}
	void pushdown(int rt)
	{
		if(!addmk[rt]) return;
		pushtag(rt*2,addmk[rt]);
		pushtag(rt*2+1,addmk[rt]);
		addmk[rt]=0;
	}
	void pushup(int rt){maxn[rt]=max(maxn[rt*2],maxn[rt*2+1]);}
	void build(int rt,int l,int r)
	{
		if(l==r) return void(maxn[rt]={0,l});
		int mid=(l+r)/2;
		build(rt*2,l,mid);
		build(rt*2+1,mid+1,r);
		pushup(rt);
	}
	void update(int rt,int l,int r,int x,int y)
	{
		if(l==r) return void(maxn[rt].first=y);
		pushdown(rt);
		int mid=(l+r)/2;
		if(x<=mid) update(rt*2,l,mid,x,y);
		else update(rt*2+1,mid+1,r,x,y);
		pushup(rt);
	}
	void update(int rt,int l,int r,int x,int y,int z)
	{
		if(l>y || r<x) return;
		if(l>=x && r<=y) return pushtag(rt,z);
		pushdown(rt);
		int mid=(l+r)/2;
		update(rt*2,l,mid,x,y,z);
		update(rt*2+1,mid+1,r,x,y,z);
		pushup(rt);
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].first);a[i].second=i;
		BIT::update(i,1);
	}
	sort(a+1,a+n+1,greater<pii>());
	for(int i=1;i<=m;i++) scanf("%d%d",&qry[i].l,&qry[i].r),qry[i].id=i;
	sort(qry+1,qry+m+1);
	S1::build(1,1,m);
	S2::build(1,1,m);
	sL.emplace(0,0);sR.emplace(n+1,m+1);
	for(int i=S1::maxn[1];i;i=S1::query(1,1,m,1,i-1))
	{
		sL.emplace(qry[i].l,i);sR.emplace(qry[i].r,i);
		S2::update(1,1,m,i,qry[i].r-qry[i].l+1);
	}
	for(int i=1,j;i<=n;i=j)
	{
		while(S2::maxn[1].first>=a[i].first+1)
		{
			int k=S2::maxn[1].second;
			ans[qry[k].id]=S2::maxn[1].first;
			assert(BIT::query(qry[k].l,qry[k].r)==ans[qry[k].id]);
			S1::update(1,1,m,k);
			S2::update(1,1,m,k,0);
			int le=prev(sL.erase(sL.find(Node(qry[k].l,k))))->id,ri=sR.erase(sR.find(Node(qry[k].r,k)))->id;
			for(int p=S1::query(1,1,m,1,ri-1);p!=le;p=S1::query(1,1,m,1,p-1))
			{
				assert(sL.emplace(qry[p].l,p).second);
				assert(sR.emplace(qry[p].r,p).second);
				S2::update(1,1,m,p,BIT::query(qry[p].l,qry[p].r));
			}
		}
		for(j=i;j<=n && a[i].first==a[j].first;j++);
		for(;i<j;i++)
		{
			int l=sR.lower_bound(Node(a[i].second,0))->id,r=(--sL.upper_bound(Node(a[i].second,0)))->id;
			if(l<=r) S2::update(1,1,m,l,r,-1);
			BIT::update(a[i].second,-1);
		}
	}
	for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3836kb

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: 3568kb

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: 3ms
memory: 3616kb

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: 0
Accepted
time: 0ms
memory: 3624kb

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
7
1
4
0
2
8
3

result:

ok 10 numbers

Test #5:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

100 100
15 82 7 39 63 55 64 99 71 63 32 99 67 94 3 43 15 75 45 55 53 4 35 36 15 40 82 20 62 43 6 83 27 95 27 45 98 44 35 98 39 7 17 32 76 7 40 16 40 63 13 8 22 27 11 12 61 14 19 45 100 97 90 88 22 59 25 63 4 25 65 16 22 92 84 44 99 66 89 26 93 97 35 97 92 1 32 40 97 97 78 43 7 12 23 53 61 74 33 90
1...

output:

68
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
48
0
0
0
0
0
0
0
0
0
0
0
0
0
28
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 100 numbers

Test #6:

score: -100
Dangerous Syscalls

input:

100 100
17 86 33 8 11 27 8 11 13 9 3 43 11 23 26 42 44 12 44 12 15 0 75 51 72 5 49 2 40 57 24 47 39 42 4 5 6 52 3 2 42 19 62 33 24 22 16 69 4 33 44 70 29 11 2 2 58 9 6 10 25 10 33 26 17 3 14 0 48 7 48 51 0 39 54 37 14 9 3 85 18 4 25 9 2 0 39 8 17 13 25 45 10 39 12 18 9 5 66 6
13 89
10 90
42 67
43 52...

output:


result: