QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#859393#8704. 排队Meatherm0 102ms7780kbC++142.2kb2025-01-17 18:31:522025-01-17 18:31:52

Judging History

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

  • [2025-01-17 18:31:52]
  • 评测
  • 测评结果:0
  • 用时:102ms
  • 内存:7780kb
  • [2025-01-17 18:31:52]
  • 提交

answer

# include <bits/stdc++.h>

const int N=300010,INF=0x3f3f3f3f;

inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-') f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}

std::mt19937 rng(114514);

struct Node{
	int val,lc,rc,rnd,siz,fa,mx;
}tr[N];
int cnt;

inline int& lc(int x){
	return tr[x].lc;
}
inline int& rc(int x){
	return tr[x].rc;
}
inline void node(int &x,int val){
	return x=++cnt,tr[x]=(Node){val,0,0,(int)rng(),1,0,val},void();
}

inline void psup(int x){
	tr[x].siz=tr[lc(x)].siz+tr[rc(x)].siz+1;
	tr[x].mx=std::min({tr[lc(x)].mx,tr[rc(x)].mx,tr[x].val});
	if(lc(x)) tr[lc(x)].fa=x;
	if(rc(x)) tr[rc(x)].fa=x;
	return;
}

void merge(int &cur,int u,int v){
	if(!u||!v) return cur=u|v,void();
	tr[u].fa=tr[v].fa=0; // ???
	if(tr[u].rnd<tr[v].rnd) cur=u,merge(rc(cur),rc(u),v);
	else cur=v,merge(lc(cur),u,lc(v));
	psup(cur);
	return;
}
void split(int cur,int &u,int &v,int k){
	if(!cur) return u=v=0,void();
	tr[cur].fa=0;
	if(tr[lc(cur)].siz+1<=k) u=cur,split(rc(cur),rc(u),v,k-tr[lc(cur)].siz-1),psup(u);
	else v=cur,split(lc(cur),u,lc(v),k),psup(v);
	return;
}
inline int getrk(int x){
	int ans=1+tr[lc(x)].siz;
	while(tr[x].fa) ans+=(tr[lc(tr[x].fa)].siz+1)*(x!=lc(tr[x].fa)),x=tr[x].fa;
	return ans;
}
void splitv(int cur,int &u,int &v,int k){
	if(!cur) return u=v=0,void();
	tr[cur].fa=0;
	if(std::min(tr[lc(cur)].mx,tr[cur].val)>=k) u=cur,split(rc(cur),rc(u),v,k),psup(u);
	else v=cur,splitv(lc(cur),u,lc(v),k),psup(v);
}

int n,T,rt; 
// idx x -> x+1

int main(void){
	T=read(),n=read(),node(rt,1); // cnt = 1
	while(n--){
		int op=read();
		if(op==1){
			int x=read(),y; node(y,cnt+1);
			if(x==0){
				merge(rt,y,rt);
			}else{
				++x;
				int k=getrk(x);
				int a,b; split(rt,a,b,k-1); merge(a,a,y); merge(rt,a,b);
			}
		}else if(op==2){
//			int y=read()+1,x=read();
//			int k=getrk(x);
//			int a,b,c; split(rt,k,a,b); splitv(b,b,c,t);
		}else{
			int y=read()+1;
			printf("%d\n",getrk(y));
		}
		
//		for(int i=1;i<=cnt;++i){
//			printf("rk = %d fa = %d size = %d lc = %d rc = %d\n",getrk(i),tr[i].fa,tr[i].siz,tr[i].lc,tr[i].rc);
//		}
	}
	 
	
	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: 0ms
memory: 3840kb

input:

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

output:

2
1

result:

wrong answer 2nd lines differ - expected: '3', found: '1'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 102ms
memory: 7780kb

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:

1
1
1
1
1
1
3
3
2
1
7
6
4
7
3
9
1
8
11
3
9
2
15
16
8
1
8
3
3
21
18
12
8
2
2
25
5
21
22
7
24
12
7
28
13
8
28
1
4
16
17
26
16
5
7
35
19
37
37
34
29
39
8
34
41
19
28
34
12
42
26
48
19
17
50
37
5
34
18
46
42
25
16
39
36
11
12
4
27
4
20
54
17
31
8
3
56
45
23
44
50
18
46
7
41
3
3
63
1
16
12
39
14
16
65
46...

result:

wrong answer 9th lines differ - expected: '1', found: '2'

Subtask #3:

score: 0
Wrong Answer

Test #20:

score: 0
Wrong Answer
time: 71ms
memory: 7732kb

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:

1
1
2
2
3
1
3
2
2
4
7
4
9
4
6
9
6
7
8
5
3
3
4
10
12
7
9
2
3
1
1
12
2
6
8
9
1
14
1
11
13
17
3
1
14
15
8
3
10
13
13
20
2
2
16
7
21
23
1
3
19
24
14
9
23
12
18
25
6
1
15
17
23
21
14
25
12
22
12
12
19
2
13
16
11
13
6
20
7
11
14
24
20
10
26
26
21
19
5
30
24
5
9
25
1
4
22
21
5
22
19
37
26
17
17
10
12
31
17...

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #35:

score: 0
Wrong Answer
time: 84ms
memory: 7728kb

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:

2
2
2
3
4
3
3
3
3
5
6
7
7
7
8
8
10
2
6
6
6
5
6
2
11
14
13
14
16
10
12
5
19
4
15
20
15
10
14
21
5
5
4
6
25
26
27
13
32
2
29
13
30
30
8
34
22
20
29
36
16
12
5
37
11
19
5
14
34
39
15
15
16
43
12
49
24
5
10
22
25
24
47
50
37
49
7
9
21
20
23
11
13
11
53
3
14
45
3
11
33
49
64
19
27
57
54
38
35
48
23
5
43
...

result:

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

Subtask #5:

score: 0
Skipped

Dependency #1:

0%