QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#342885#4909. 《关于因为与去年互测zjk撞题而不得不改题这回事》madefa10 73ms60488kbC++142.7kb2024-03-01 19:12:552024-03-01 19:12:56

Judging History

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

  • [2024-03-01 19:12:56]
  • 评测
  • 测评结果:10
  • 用时:73ms
  • 内存:60488kb
  • [2024-03-01 19:12:55]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long 
const int N=1e6+10;
const int M=1e5+10;
const int V=63;
using namespace std;
int n,q;
int head[N],ve[N*2],ne[N*2],tot;
void add(int a,int b){
	ve[++tot]=b;
	ne[tot]=head[a];
	head[a]=tot;
}
int len;
int b[N],a[N];
struct tree{
	int ls,rs,sum;
}s[N*25];
int dir;
int f[N][23],dep[N],rt[N];
int change(int root,int l,int r,int val){
	int now=++dir;
	s[now].ls=s[root].ls;s[now].rs=s[root].rs;s[now].sum=s[root].sum+1;
	if(l==r)return dir; 
	int mid=(l+r)>>1;
	if(mid>=val) s[now].ls=change(s[now].ls,l,mid,val);
	else s[now].rs=change(s[now].rs,mid+1,r,val);
	return now;
}
void dfs(int x,int fa){
	f[x][0]=fa;
	dep[x]=dep[fa]+1;
	rt[x]=change(rt[fa],1,len,a[x]);
	for(int i=1;i<=21;i++){
		f[x][i]=f[f[x][i-1]][i-1];
	}
	for(int i=head[x];i;i=ne[i]){
		int y=ve[i];
		if(y==fa)continue;
		dfs(y,x);
	}
}
int LCA(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	for(int i=21;i>=0;i--){
		if(dep[f[x][i]]>=dep[y]){
			x=f[x][i];
		}
		if(x==y)return x;
	}
	for(int i=21;i>=0;i--){
		if(f[x][i]!=f[y][i]){
			x=f[x][i];
			y=f[y][i];
		}
	}
	return f[x][0];
}
int lastans;
int lim,cnt,cnt1;
int st[N],st1[N];
void query(int u,int v,int lca,int flca,int l,int r){
	if(!lim||!(s[u].sum+s[v].sum-s[lca].sum-s[flca].sum))return;
	if(l==r){
		int add=min(lim,s[u].sum+s[v].sum-s[lca].sum-s[flca].sum);
		lim-=add;
		while(add){
			st[++cnt]=b[l];add--;
		}
		return;
	}
	int mid=(l+r)>>1;
	query(s[u].rs,s[v].rs,s[lca].rs,s[flca].rs,mid+1,r);
	query(s[u].ls,s[v].ls,s[lca].ls,s[flca].ls,l,mid);
}
void solve(int x,int y,int m){
	
	int lca=LCA(x,y);
	lim=200;cnt=0;
//	printf("x=%lld y=%lld m=%lld\n",x,y,m);
//	printf("lca=%lld flca=%lld\n",lca,f[lca][0]);
	query(rt[x],rt[y],rt[lca],rt[f[lca][0]],1,len);
	int ans=0;
//	for(int i=1;i<=cnt;i++){
//		printf("st%lld=%lld\n",i,st[i]);
//	}
	for(int i=61;i>0;i--){
		ans|=(1<<(i-1));
		cnt1=0;
		for(int j=1;j<=cnt;j++){
			if(st[j]&(1<<(i-1))){
				st1[++cnt1]=st[j];
			}
		}
		if(cnt1<m)ans^=(1<<(i-1));
		else{
			cnt=cnt1;
			for(int j=1;j<=cnt1;j++)st[j]=st1[j];
		}
	}
	lastans=ans;
	printf("%lld\n",ans);
}
signed main(){
 	scanf("%lld",&n);
 	for(int i=1;i<n;i++){
 		int u,v;
 		scanf("%lld%lld",&u,&v);
 		add(u,v);add(v,u);
 	}
 	for(int i=1;i<=n;i++){
 		scanf("%lld",&a[i]);
 		b[i]=a[i];
 	}
 	sort(b+1,b+n+1);
 	len=unique(b+1,b+n+1)-b-1;
 	for(int i=1;i<=n;i++){
 		a[i]=lower_bound(b+1,b+len+1,a[i])-b;
 	}
	dfs(1,0);
	scanf("%lld",&q);
	while(q--){
		int x,y,m;
		scanf("%lld%lld%lld",&x,&y,&m);
		x=((x^lastans)%n)+1;y=((y^lastans)%n)+1;
		solve(x,y,m);
	}
/*
5
1 2
3 1
4 3
5 4
274 5134 2066 17120 40972 
3
4 4 2
3 1 2
1 4 2
*/
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 16556kb

input:

931
184 700
485 184
419 485
386 419
308 386
114 308
301 114
598 301
120 598
144 120
595 144
812 595
236 812
7 236
543 7
327 543
858 327
68 858
177 68
398 177
899 398
408 899
848 408
202 848
269 202
304 269
540 304
647 540
672 647
314 672
157 314
241 157
745 241
300 745
343 300
92 343
117 92
30 117
2...

output:

268435584

result:

wrong answer 1st numbers differ - expected: '1152921504606846976', found: '268435584'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 10
Accepted

Test #17:

score: 10
Accepted
time: 35ms
memory: 56436kb

input:

99115
98506 98914
1961 98506
45808 1961
23027 45808
16655 23027
66393 16655
77250 66393
68284 77250
53684 68284
21189 53684
84955 21189
73464 84955
47574 73464
40651 47574
21101 40651
6589 21101
59680 6589
6185 59680
25529 6185
207 25529
33286 207
98459 33286
92565 98459
85446 92565
97388 85446
1630...

output:

2050

result:

ok 1 number(s): "2050"

Test #18:

score: 0
Accepted
time: 46ms
memory: 56952kb

input:

99546
79711 12863
50539 79711
13393 50539
27933 13393
13465 27933
79157 13465
53742 79157
51081 53742
32220 51081
21079 32220
85595 21079
50222 85595
14565 50222
4589 14565
13763 4589
58913 13763
93835 58913
34953 93835
2185 34953
10246 2185
64420 10246
44274 64420
63093 44274
8007 63093
85947 8007
...

output:

512

result:

ok 1 number(s): "512"

Test #19:

score: 0
Accepted
time: 27ms
memory: 60132kb

input:

99762
90013 76047
42293 90013
7801 42293
75274 7801
59320 75274
60896 59320
10435 60896
5384 10435
34648 5384
15596 34648
92041 15596
67457 92041
20760 67457
65611 20760
81462 65611
38984 81462
17583 38984
83787 17583
59980 83787
71477 59980
31143 71477
92168 31143
71205 92168
69348 71205
6111 69348...

output:

16386

result:

ok 1 number(s): "16386"

Test #20:

score: 0
Accepted
time: 42ms
memory: 59080kb

input:

99132
46469 40521
51811 46469
47968 51811
10584 47968
73 10584
27351 73
16693 27351
12495 16693
53425 12495
95973 53425
24901 95973
82771 24901
49155 82771
35995 49155
50432 35995
91209 50432
5781 91209
83457 5781
41361 83457
37973 41361
48829 37973
62896 48829
77593 62896
21307 77593
86547 21307
61...

output:

8194

result:

ok 1 number(s): "8194"

Test #21:

score: 0
Accepted
time: 37ms
memory: 57656kb

input:

99403
81802 91324
60321 81802
76749 60321
70097 76749
16085 70097
8301 16085
61886 8301
72994 61886
23906 72994
18815 23906
6781 18815
7774 6781
18318 7774
54769 18318
39330 54769
55677 39330
46758 55677
36164 46758
10159 36164
24678 10159
29603 24678
14941 29603
7966 14941
42934 7966
35909 42934
24...

output:

32770

result:

ok 1 number(s): "32770"

Test #22:

score: 0
Accepted
time: 73ms
memory: 60488kb

input:

99468
33859 68644
12306 33859
44304 12306
18200 44304
27325 18200
35907 27325
88149 35907
71599 88149
86384 71599
83793 86384
19513 83793
4843 19513
3007 4843
52878 3007
83019 52878
5275 83019
61517 5275
21453 61517
55993 21453
50710 55993
16211 50710
76061 16211
12048 76061
41970 12048
86181 41970
...

output:

514

result:

ok 1 number(s): "514"

Test #23:

score: 0
Accepted
time: 40ms
memory: 56820kb

input:

99179
45430 91876
8718 45430
75718 8718
15306 75718
21806 15306
78221 21806
74287 78221
66218 74287
66830 66218
64948 66830
16118 64948
33879 16118
81821 33879
69640 81821
27802 69640
25979 27802
6393 25979
63447 6393
48459 63447
53612 48459
27525 53612
52654 27525
80810 52654
767 80810
23808 767
82...

output:

32768

result:

ok 1 number(s): "32768"

Test #24:

score: 0
Accepted
time: 34ms
memory: 56820kb

input:

99240
8561 98467
49571 8561
13264 49571
94195 13264
85879 94195
53012 85879
29828 53012
25813 29828
57793 25813
10678 57793
88525 10678
70070 88525
54163 70070
51466 54163
3857 51466
77958 3857
29023 77958
154 29023
5173 154
4349 5173
24310 4349
21821 24310
36125 21821
75498 36125
7147 75498
22336 7...

output:

32770

result:

ok 1 number(s): "32770"

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Memory Limit Exceeded

Test #45:

score: 0
Memory Limit Exceeded

input:

996678
2 1
3 1
4 1
5 1
6 3
7 5
8 5
9 5
10 7
11 8
12 9
13 1
14 2
15 7
16 4
17 5
18 17
19 16
20 2
21 1
22 1
23 9
24 17
25 19
26 10
27 9
28 7
29 25
30 25
31 4
32 11
33 31
34 21
35 13
36 19
37 25
38 10
39 11
40 20
41 35
42 1
43 19
44 20
45 41
46 1
47 19
48 5
49 28
50 21
51 33
52 7
53 14
54 21
55 20
56 1...

output:

4
0
4
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
8
0
0
0
0
16
0
0
4096
0
0
0
0
4096
0
0
0
0
2
0
0
0
0
4
0
0
0
0
32
64
0
0
0
512
64
4
4096
0
2
0
0
131072
0
0
0
0
0
0
0
0
2
0
0
0
2
0
4096
2
0
0
0
0
0
512
2
8
0
0
4096
64
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
512
0
0
36
0
0
0
0
0
0
0
64
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:


Subtask #8:

score: 0
Skipped

Dependency #1:

0%