QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#820434#8704. 排队RandomShuffle0 49ms69508kbC++142.1kb2024-12-18 21:26:202024-12-18 21:26:20

Judging History

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

  • [2024-12-18 21:26:20]
  • 评测
  • 测评结果:0
  • 用时:49ms
  • 内存:69508kb
  • [2024-12-18 21:26:20]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define gc getchar
int rd(){
	int f=1,r=0;
	char ch=gc();
	while(!isdigit(ch)){ if(ch=='-') f=-1;ch=gc();}
	while(isdigit(ch)){ r=(r<<3)+(r<<1)+(ch^48);ch=gc();}
	return f*r;
}

void wt(int x){
	if(x/10) wt(x/10);
	putchar(x%10+'0');
}

mt19937 rnd(19260817);
const int maxn=1e6+10;
int n,Q,tot,rt,l[maxn],r[maxn],num[maxn],ans[maxn];
vector<int> q[maxn],rm[maxn];
struct FHQ{
	int val,rv,tag,fa,ch[2];
}t[maxn];

#define ls(u) (t[u].ch[0])
#define rs(u) (t[u].ch[1])

inline void pushup(int u){
	if(ls(u)) t[ls(u)].fa=u;
	if(rs(u)) t[rs(u)].fa=u;
}

inline void pushdown(int u){
	if(t[u].tag){
		t[ls(u)].val+=t[u].tag;
		t[rs(u)].val+=t[u].tag;
		t[ls(u)].tag+=t[u].tag;
		t[rs(u)].tag+=t[u].tag;
		t[u].tag=0;
	}
}

void pushall(int u){
	if(t[u].fa) pushall(t[u].fa);
	pushdown(u);
}

inline int newnode(){
	t[++tot].val=0;
	t[tot].rv=rnd();
	return tot;
}

void splitv(int u,int v,int &l,int &r){
	t[ls(u)].fa=t[rs(u)].fa=0;
	if(!u){
		l=r=0;
		return;
	}
	pushdown(u);
	if(t[u].val<=v) l=u,splitv(rs(u),v,rs(l),r);
	else r=u,splitv(ls(u),v,l,ls(r));
	pushup(u);
}

void merge(int &u,int l,int r){
	t[ls(u)].fa=t[rs(u)].fa=0;
	if(!l||!r){
		u=l+r;
		if(u) pushup(u);
		return;
	}
	if(t[l].rv>t[r].rv) u=l,pushdown(u),merge(rs(u),rs(l),r);
	else u=r,pushdown(u),merge(ls(u),l,ls(r));
	pushup(u);
}

void insert(){
	merge(rt,newnode(),rt);
}

int main(){
	n=rd(),Q=rd();
	for(int i=1;i<=n;++i) l[i]=rd(),r[i]=rd();
	for(int i=1;i<=Q;++i){
		int ql=rd(),qr=rd();
		q[ql].emplace_back(i);
		rm[qr].emplace_back(i);
	}
	for(int i=1;i<=n;++i){
		for(int j=0;j<(int)q[i].size();++j){
			insert();
			num[q[i][j]]=tot;
		}
		int rt1=0;
		splitv(rt,r[i],rt1,rt);
		int rt2=0;
		splitv(rt1,l[i]-1,rt2,rt1);
		t[rt1].tag++;
		t[rt1].val++;
		merge(rt1,rt2,rt1);
		merge(rt,rt1,rt);
		for(int j=0;j<(int)rm[i].size();++j){
			int p=rm[i][j];
			pushall(num[p]);
			ans[p]=t[num[p]].val;
		}
	}
	for(int i=1;i<=Q;++i) wt(ans[i]),putchar('\n');
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

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

output:

0
0
0
0
0
0
0
0

result:

wrong answer 1st lines differ - expected: '2', found: '0'

Subtask #2:

score: 0
Time Limit Exceeded

Test #5:

score: 0
Time Limit Exceeded

input:

1 298913
1 0
3 1
3 1
3 1
3 1
3 1
1 0
1 0
3 3
1 2
1 2
3 5
3 5
1 1
1 3
1 4
3 3
1 3
1 6
3 7
3 2
3 5
3 8
3 2
1 8
3 3
1 4
3 2
3 7
1 3
3 4
1 10
3 14
3 13
1 12
3 4
1 8
1 15
1 16
3 9
3 14
3 10
3 8
3 7
1 16
1 15
3 16
3 13
1 19
3 13
3 1
3 14
1 18
1 22
3 8
1 17
3 18
3 9
1 18
3 9
3 1
1 20
3 11
3 5
3 2
3 22
1 22...

output:


result:


Subtask #3:

score: 0
Wrong Answer

Test #20:

score: 0
Wrong Answer
time: 45ms
memory: 63972kb

input:

2 298235
1 0
1 1
3 2
1 0
1 3
3 4
3 3
3 3
3 2
3 4
3 2
3 3
1 2
3 3
1 4
1 2
1 1
3 5
3 8
1 5
1 9
3 10
3 8
3 10
3 5
3 8
3 5
1 2
1 9
3 5
3 7
3 12
3 3
1 6
3 4
3 3
3 11
3 8
3 9
3 7
3 6
3 4
1 12
1 11
3 13
3 13
1 11
3 16
3 6
3 14
3 9
3 5
3 13
1 9
1 17
3 16
3 13
3 5
3 15
3 8
3 4
3 13
1 18
3 15
3 16
3 19
3 4
1 ...

output:

6
0
0
0
0
0
6
0
6
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
0
6
0
0
0
0
0
6
3
0
0
0
0
3
0
0
0
0
0
0
3
0
0
0
0
6
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
6
0
...

result:

wrong answer 1st lines differ - expected: '2', found: '6'

Subtask #4:

score: 0
Wrong Answer

Test #35:

score: 0
Wrong Answer
time: 49ms
memory: 69508kb

input:

3 299743
1 0
1 1
3 1
1 2
3 2
1 0
3 3
3 2
3 1
3 2
2 2 1
3 3
3 3
3 4
3 1
3 2
3 2
2 1 0
3 2
3 1
3 1
1 0
3 2
1 2
1 1
3 2
2 5 2
1 6
1 0
2 5 2
1 7
3 8
3 5
3 5
2 7 5
2 9 4
3 5
3 8
2 6 2
2 3 0
2 2 0
1 1
2 3 1
1 8
2 7 0
3 3
1 12
2 13 9
1 5
2 2 1
2 14 13
1 12
2 1 0
2 12 10
2 15 12
1 0
1 6
3 6
2 3 2
2 17 6
3 4...

output:

0
6
0
0
6
3
6
0
0
0
0
9
0
0
0
0
6
3
3
0
6
0
0
6
0
3
3
6
6
0
0
0
0
0
6
0
0
0
0
0
0
0
3
0
3
0
0
9
3
6
0
0
0
0
0
0
3
6
0
0
3
3
9
6
6
0
9
3
3
9
3
9
3
9
3
0
3
9
9
6
0
0
3
9
3
6
0
0
0
9
6
6
0
0
0
0
6
6
0
0
0
0
0
9
6
0
0
0
0
9
9
6
0
0
0
0
6
0
0
0
3
3
6
3
0
0
0
0
0
0
0
0
0
0
9
3
3
3
6
0
0
0
9
9
9
3
3
3
9
3
...

result:

wrong answer 1st lines differ - expected: '1', found: '0'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%