QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#412939#8672. 排队g1ove0 12ms45104kbC++141.9kb2024-05-16 21:53:212024-05-16 21:53:22

Judging History

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

  • [2024-05-16 21:53:22]
  • 评测
  • 测评结果:0
  • 用时:12ms
  • 内存:45104kb
  • [2024-05-16 21:53:21]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define N 1000005
using namespace std;
const int inf=1e4+5;
int n,m;
int l[N],r[N];
int stk[N],top;
struct segtree{
	int tr[N*4],lz[N*4],p[N*4];
	void Pushup(int x)
	{
		if(tr[x*2]<=tr[x*2+1]) tr[x]=tr[x*2],p[x]=p[x*2];
		else tr[x]=tr[x*2+1],p[x]=p[x*2+1];
	} 
	void Pushdown(int x)
	{
		if(!lz[x]) return;
		tr[x*2]+=lz[x];
		tr[x*2+1]+=lz[x];
		lz[x*2]+=lz[x];
		lz[x*2+1]+=lz[x];
		lz[x]=0;
	}
	void modify(int l,int r,int L,int R,int x,int v)
	{
		if(l>R||r<L) return;
		if(l>=L&&r<=R)
		{
			tr[x]+=v;
			lz[x]+=v;
			if(l==r) p[x]=l;
			return;
		}
		int mid=(l+r)/2;
		Pushdown(x);
		modify(l,mid,L,R,x*2,v);
		modify(mid+1,r,L,R,x*2+1,v);
		Pushup(x);
	}
	int query(int l,int r,int p,int x)
	{
		if(l==r) return tr[x];
		int mid=(l+r)/2;
		Pushdown(x);
		if(p<=mid) return query(l,mid,p,x*2);
		else return query(mid+1,r,p,x*2+1);
	}
}tr1,tr2,tr3;
int ans[N];
struct node{
	int p,id;
};
vector<node> E[N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&l[i],&r[i]);
	tr1.modify(1,n,1,n,1,inf);
	tr2.modify(1,n,1,n,1,inf);
	for(int i=1;i<=m;i++)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		E[l].push_back((node){r,i});
	}
	for(int i=n;i>=1;i--)
	{
		tr1.modify(1,n,i,i,1,l[i]-inf);
		tr2.modify(1,n,i,i,1,r[i]+1-inf);
		while(1)
		{
			int l1=tr1.p[1],l2=tr2.p[1];
			if(tr1.tr[1]>0&&tr2.tr[1]>0) break;
			if(tr1.tr[1]>0) l1=inf;
			if(tr2.tr[1]>0) l2=inf;
			if(l1<l2)
			{
				tr1.modify(1,n,l1,l1,1,inf);
				tr1.modify(1,n,l1+1,n,1,-1);
				tr2.modify(1,n,l1+1,n,1,-1);
				tr3.modify(1,n,l1,n,1,1);
			}
			else
			{
				tr2.modify(1,n,l2,l2,1,inf);
				tr1.modify(1,n,l2+1,n,1,1);
				tr2.modify(1,n,l2+1,n,1,1);
				tr3.modify(1,n,l2,n,1,-1);
			}
		}
		for(auto u:E[i]) ans[u.id]=tr3.query(1,n,u.p,1);
	}
	for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 3ms
memory: 45104kb

input:

3 3
0 0
1 2
0 2
1 1
1 3
2 3

output:

1
3
1

result:

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

Test #2:

score: 0
Wrong Answer
time: 12ms
memory: 44024kb

input:

5000 5000
5 10
3 9
3 8
2 7
2 5
3 6
1 5
0 2
7 8
2 10
0 3
3 6
4 6
1 6
4 8
7 8
2 7
3 4
4 9
7 8
2 9
2 5
3 6
0 5
6 7
1 2
2 4
2 10
1 5
7 9
6 9
2 3
9 10
5 5
2 9
3 3
2 7
2 4
0 6
0 3
1 7
7 7
4 8
2 9
4 8
0 10
1 8
1 1
2 7
5 9
1 7
1 7
1 4
2 4
1 4
2 9
1 7
4 7
3 8
1 3
4 6
1 5
1 6
0 0
3 9
4 7
2 8
1 8
1 2
7 8
2 7
2...

output:

11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
...

result:

wrong answer 3023rd numbers differ - expected: '8', found: '9'

Subtask #2:

score: 0
Time Limit Exceeded

Test #12:

score: 0
Time Limit Exceeded

input:

200000 200000
3 6
3 3
6 10
1 7
2 7
6 9
4 6
3 4
0 8
0 6
3 5
3 4
1 8
7 8
4 5
0 3
1 5
2 9
1 2
1 2
3 4
5 7
6 10
3 9
4 7
1 6
2 6
1 7
2 5
1 7
6 8
1 1
0 7
7 8
0 9
1 7
3 8
3 7
1 2
4 8
5 6
0 6
5 6
2 7
2 6
0 6
0 6
1 7
2 5
0 3
0 3
7 10
3 8
0 2
3 4
3 7
4 9
0 6
4 7
2 6
8 10
2 10
4 10
3 3
2 6
4 5
3 9
1 8
1 2
2 9
...

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #22:

score: 0
Time Limit Exceeded

input:

200000 200000
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 0
0 9
0 10
0 0
0 0
0 13
0 14
0 0
0 16
0 17
0 18
0 19
0 0
0 21
0 22
0 23
0 0
0 0
0 0
0 0
0 28
0 0
0 30
0 31
0 32
0 33
0 34
0 35
0 0
0 0
0 38
0 39
0 40
0 41
0 42
0 43
0 44
0 45
0 46
0 0
0 48
0 49
0 50
0 51
0 52
0 53
0 54
0 55
0 56
0 57
0 0
0 59
0 60
0 0
0 0
...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #32:

score: 0
Time Limit Exceeded

input:

200000 200000
0 200000
1 200000
1 200000
0 200000
0 200000
1 200000
1 200000
1 200000
0 200000
1 200000
0 200000
0 200000
1 200000
0 200000
0 200000
0 200000
0 200000
1 200000
0 200000
0 200000
1 200000
0 200000
1 200000
1 200000
1 200000
1 200000
0 200000
0 200000
1 200000
2 200000
1 200000
2 20000...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%