QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#549154#3279. 经典游戏Flamire#56 238ms161400kbC++173.7kb2024-09-06 10:37:332024-09-06 10:37:35

Judging History

This is the latest submission verdict.

  • [2024-09-06 10:37:35]
  • Judged
  • Verdict: 56
  • Time: 238ms
  • Memory: 161400kb
  • [2024-09-06 10:37:33]
  • Submitted

answer

#include <bits/stdc++.h>
#define N 1000011
#define M N*23
using namespace std;
int n,m;
vector<int> G[N];
int ch[M][2],cnt[M],rt[N],gb[M],a[N];
struct BIT
{
	int c[N];
	int query(int x){int ans=0;for(;x;x-=x&-x)ans^=c[x];return ans;}
	void add(int x,int p){for(;x<=n;x+=x&-x)c[x]^=p;}
	void add(int l,int r,int p){if(l>r)return;add(l,p);add(r+1,p);}
}Bt,Bx;
void ins(int v,int x)
{//printf("ins(v:%d,x:%d)\n",v,x);
	for(int i=19;~i;--i)
	{
		++cnt[x];
		// printf("i:%d x:%d cnt:%d\n",i,x,cnt[x]);
		if(!ch[x][v>>i&1])
		{
			int nw=gb[gb[0]--];ch[nw][0]=ch[nw][1]=cnt[nw]=0;
			ch[x][v>>i&1]=nw;
		}
		x=ch[x][v>>i&1];
	}
	++cnt[x];
}
void del(int v,int x)
{//printf("del(v:%d,x:%d)\n",v,x);
	int lst=x;
	for(int i=19;~i;--i)
	{
		if((!--cnt[x])&&i<19)gb[++gb[0]]=x,ch[lst][v>>i+1&1]=0;
		// printf("i:%d x:%d cnt:%d\n",i,x,cnt[x]);
		lst=x;
		x=ch[x][v>>i&1];
	}
	if(!--cnt[x])gb[++gb[0]]=x;
}
int search(int x,int tag,int v)
{//printf("search(x:%d,tag:%d,v:%d)\n",x,tag,v);
	int ans=0;
	for(int i=19;~i;--i)
	{
		// printf("i:%d x:%d cnt:%d\n",i,x,cnt[x]);
		if(v>>i&1)ans+=cnt[ch[x][((v^tag)>>i&1)^1]];
		x=ch[x][(v^tag)>>i&1];
	}
	ans+=cnt[x];
	// printf("ans:%d\n",ans);
	return ans;
}
int S,T,C,Cu,Cv,D,dep[N],fa[N],dfn[N],siz[N],rk[N],clk;
void dfsd(int u,int F)
{
	dep[u]=dep[F]+1;fa[u]=F;
	for(int v:G[u])if(v^F)dfsd(v,u);
}
int h[N],fah[N],X[N];
void dfs(int u,int F,int H)
{
	fa[u]=F;
	dfn[u]=++clk;rk[clk]=u;siz[u]=1;fah[u]=H;
	for(int v:G[u])if(v^F)dfs(v,u,H+1),siz[u]+=siz[v],h[u]=max(h[u],h[v]+1);
}
void addnode(int u)
{
	// printf("----addnode(%d)\n",u);
	Bt.add(dfn[u],dfn[u]+siz[u]-1,fah[u]);
	Bt.add(1,dfn[u]-1,h[u]);Bt.add(dfn[u]+siz[u],n,h[u]);
	if(fa[u]&&u!=Cu&&u!=Cv)
	{
		del(X[u],rt[fa[u]]);
		X[u]^=h[u]^max(h[u],fah[u]);
		ins(X[u],rt[fa[u]]);
	}
	Bx.add(dfn[u]+1,dfn[u]+siz[u]-1,fah[u]);
	Bx.add(1,dfn[u]-1,h[u]);Bx.add(dfn[u]+siz[u],n,h[u]);
	Bx.add(dfn[u],dfn[u],max(h[u],fah[u]));
		// printf("Bt:");for(int i=1;i<=n;++i)printf("%d ",Bt.query(dfn[i]));putchar(10);
		// printf("X:");for(int i=1;i<=n;++i)printf("%d ",X[i]);putchar(10);
		// printf("Bx:");for(int i=1;i<=n;++i)printf("%d ",Bx.query(dfn[i]));putchar(10);
		// for(int i=1;i<=n;++i)if(fa[i]&&i!=Cu&&i!=Cv)assert((Bt.query(dfn[fa[i]])^X[i])==Bx.query(dfn[i]));
}
bool check(int y)
{
	// printf("y:%d Bx:%d H:%d\n",y,Bx.query(dfn[y]),max(h[y],fah[y]));
	return Bx.query(dfn[y])<=max(h[y],fah[y]);
}
int main()
{
	scanf("%*d%d%d",&n,&m);
	for(int i=1;i<n;++i){int u,v;scanf("%d%d",&u,&v);G[u].push_back(v);G[v].push_back(u);}
	for(int i=1;i<=n;++i)scanf("%d",a+i),a[i]&=1;
	dfsd(1,0);
	for(int i=1;i<=n;++i)if(dep[i]>dep[S])S=i;
	dfsd(S,0);
	for(int i=1;i<=n;++i)if(dep[i]>dep[T])T=i;
	D=dep[T]-1;
	C=T;
	for(int _=0;_<D/2;++_)C=fa[C];
	for(int i=M-1;i;--i)gb[++gb[0]]=i;
	// printf("D:%d\n",D);
	if(D&1)
	{
		Cu=C,Cv=fa[C];C=0;
		// printf("D:%d Cu:%d Cv:%d\n",D,Cu,Cv);
		dfs(Cu,Cv,(D+1)/2);
		dfs(Cv,Cu,(D+1)/2);
	}
	else
	{
		dfs(C,0,D/2);
	}
	for(int i=1;i<=n;++i){rt[i]=gb[gb[0]--];for(int _=1;_<=G[i].size()-(i!=C);++_)ins(0,rt[i]);}
	// for(int i=1;i<=n;++i)assert(h[i]<=fah[i]);
	for(int i=1;i<=n;++i)if(a[i])addnode(i);
	while(m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		addnode(x);
		int ans=0,cnt=G[y].size()+1;
		ans+=check(y);if(fa[y])ans+=check(fa[y]);
		ans+=search(rt[y],Bt.query(dfn[y]),fah[y]+1);
		// for(int z:G[y])ans+=check(z);
		// ans+=check(y);
		printf("%d\n",cnt-ans);
		// printf("Bt:");for(int i=1;i<=n;++i)printf("%d ",Bt.query(dfn[i]));putchar(10);
		// printf("X:");for(int i=1;i<=n;++i)printf("%d ",X[i]);putchar(10);
		// printf("Bx:");for(int i=1;i<=n;++i)printf("%d ",Bx.query(dfn[i]));putchar(10);
	}
	fclose(stdin);fclose(stdout);return 0;
}

詳細信息

Subtask #1:

score: 16
Accepted

Test #1:

score: 16
Accepted
time: 61ms
memory: 122828kb

input:

16
5 5
4 3
3 2
3 5
3 1
0 1 1 0 1
5 2
5 5
4 2
2 1
3 2

output:

1
1
1
0
0

result:

ok 5 number(s): "1 1 1 0 0"

Test #2:

score: 16
Accepted
time: 57ms
memory: 123168kb

input:

16
5 5
2 4
4 3
3 5
2 1
0 1 1 0 1
3 2
3 5
1 2
4 1
5 3

output:

0
1
1
0
0

result:

ok 5 number(s): "0 1 1 0 0"

Subtask #2:

score: 15
Accepted

Dependency #1:

100%
Accepted

Test #3:

score: 15
Accepted
time: 47ms
memory: 121956kb

input:

15
300 300
2 49
5 174
7 98
12 254
14 234
21 3
3 11
26 48
29 102
32 232
35 283
36 130
38 22
39 178
40 294
44 192
46 256
47 99
53 58
54 287
55 268
56 207
57 238
58 34
34 207
59 226
63 202
70 13
13 128
73 76
76 261
83 285
84 6
89 217
90 294
94 230
101 155
104 273
106 15
107 52
108 276
110 118
111 285
1...

output:

0
0
3
0
2
1
2
0
0
2
1
0
0
0
2
0
0
2
0
0
0
2
0
2
0
0
1
0
0
0
0
1
0
0
0
2
1
0
2
1
0
0
0
1
0
1
0
0
0
0
0
0
3
2
1
0
0
1
2
1
2
0
2
0
0
3
2
0
1
4
1
0
0
3
0
0
0
3
2
0
0
2
2
0
0
0
0
1
1
3
0
0
0
1
0
0
0
0
2
0
0
0
0
2
2
1
3
0
0
0
0
0
0
3
0
0
0
3
0
0
0
0
2
1
0
0
1
0
0
0
2
1
0
2
0
0
0
0
1
0
0
1
0
1
0
0
0
0
0
2
...

result:

ok 300 numbers

Test #4:

score: 15
Accepted
time: 54ms
memory: 122000kb

input:

15
300 300
2 296
7 137
9 253
11 107
12 298
16 274
18 81
22 51
24 113
25 216
26 254
27 300
30 289
31 180
32 221
33 113
34 225
36 298
46 163
48 258
49 220
50 189
52 268
53 207
55 128
59 74
63 67
65 181
71 70
72 5
5 272
74 135
77 252
80 42
83 28
84 127
86 57
57 141
91 232
92 262
96 181
97 287
98 118
99...

output:

1
0
0
0
0
0
0
0
0
0
0
0
1
0
1
1
0
0
0
1
1
0
3
1
3
0
1
0
3
0
2
2
0
5
4
0
0
1
0
1
2
4
0
2
3
2
0
2
2
2
1
3
2
1
2
2
2
1
3
2
2
0
3
1
1
1
3
2
0
0
4
1
0
0
0
0
2
3
0
0
2
0
1
2
1
2
1
0
1
0
0
0
3
2
0
0
1
2
2
0
0
0
0
0
0
3
0
0
1
0
1
0
0
1
0
1
0
0
2
0
0
3
2
1
2
1
2
1
2
0
2
2
1
1
1
0
1
3
0
3
1
0
0
2
2
1
0
1
2
2
...

result:

ok 300 numbers

Test #5:

score: 15
Accepted
time: 68ms
memory: 123080kb

input:

15
300 300
2 240
7 129
8 82
23 13
27 189
29 274
32 75
36 191
38 131
40 268
44 202
46 223
47 223
48 216
52 276
53 78
55 39
39 169
57 215
59 201
60 110
63 112
64 102
65 166
75 19
77 276
80 49
49 4
4 215
84 143
85 87
87 156
89 58
92 219
95 54
54 137
97 42
42 15
15 74
98 17
99 168
100 296
101 14
103 161...

output:

0
1
1
2
2
3
0
2
2
0
0
0
1
0
2
0
1
0
0
0
1
0
4
0
2
3
0
0
0
0
1
0
0
1
0
3
1
0
3
2
2
2
2
2
1
2
0
2
1
2
1
0
2
1
0
2
2
3
0
0
0
2
1
2
2
4
0
1
3
0
0
2
2
2
1
2
3
3
0
3
1
2
2
0
4
1
3
2
1
3
0
1
0
1
1
1
1
0
1
1
1
0
2
2
0
0
0
0
0
3
0
0
0
0
1
3
0
2
3
2
0
3
1
0
2
0
1
0
1
1
1
2
0
0
0
1
2
1
0
0
0
1
0
3
3
0
0
1
0
1
...

result:

ok 300 numbers

Subtask #3:

score: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #6:

score: 0
Wrong Answer
time: 64ms
memory: 123552kb

input:

14
5000 5000
1 4135
2 31
7 4379
9 2889
13 3400
18 3575
19 2290
21 2220
24 1553
29 3843
31 4336
34 3761
36 4515
37 819
38 653
39 3034
45 4752
52 2852
57 3982
60 3301
67 3785
69 4902
71 942
72 2868
77 919
80 2748
81 2624
82 1902
84 3498
87 3279
88 4583
91 4452
96 1669
99 2196
100 2151
102 3725
104 234...

output:

3
2
0
1
1
3
3
0
0
2
0
0
0
3
1
2
0
2
1
0
3
0
0
2
3
1
0
1
0
1
2
1
1
1
2
1
0
2
0
3
0
0
0
0
2
0
2
2
2
0
1
2
1
0
4
3
1
2
4
0
0
1
0
1
0
2
1
0
0
2
2
1
3
2
0
1
2
0
3
0
3
0
3
2
2
2
0
1
0
0
1
0
3
2
3
2
2
1
2
0
0
0
0
1
2
0
2
0
0
0
3
1
1
1
1
4
2
0
2
0
0
3
0
1
4
0
1
0
0
0
2
0
2
0
0
0
1
0
1
0
0
3
0
0
0
3
1
2
0
0
...

result:

wrong answer 2579th numbers differ - expected: '2', found: '1'

Subtask #4:

score: 13
Accepted

Test #9:

score: 13
Accepted
time: 219ms
memory: 158532kb

input:

13
100000 100000
91699 52443
52443 41748
41748 32330
32330 42277
42277 80707
80707 97074
97074 84439
84439 73656
73656 94232
94232 19271
19271 64725
64725 68032
68032 15074
15074 98785
98785 84234
84234 63617
63617 85713
85713 32965
32965 90099
90099 95398
95398 84273
84273 90891
90891 89305
89305 9...

output:

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

result:

ok 100000 numbers

Test #10:

score: 13
Accepted
time: 219ms
memory: 159144kb

input:

13
100000 100000
57624 99869
99869 80198
80198 62843
62843 7883
7883 52607
52607 69363
69363 97085
97085 63315
63315 86299
86299 96455
96455 76868
76868 43868
43868 54746
54746 90151
90151 63572
63572 92398
92398 79264
79264 66180
66180 61719
61719 97795
97795 91813
91813 98698
98698 81039
81039 904...

output:

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

result:

ok 100000 numbers

Test #11:

score: 13
Accepted
time: 238ms
memory: 161400kb

input:

13
100000 100000
64496 84832
84832 93531
93531 39916
39916 52794
52794 79600
79600 82783
82783 66851
66851 79473
79473 85703
85703 26977
26977 79380
79380 92594
92594 64565
64565 59553
59553 96967
96967 76192
76192 99410
99410 7785
7785 95668
95668 68456
68456 59935
59935 94596
94596 65080
65080 628...

output:

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

result:

ok 100000 numbers

Test #12:

score: 13
Accepted
time: 224ms
memory: 158656kb

input:

13
100000 100000
84707 21587
21587 22506
22506 89794
89794 88141
88141 95218
95218 41382
41382 91979
91979 87575
87575 52697
52697 89043
89043 82196
82196 79424
79424 77887
77887 33683
33683 95806
95806 92247
92247 94484
94484 47740
47740 25904
25904 56736
56736 68596
68596 93904
93904 96199
96199 3...

output:

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

result:

ok 100000 numbers

Subtask #5:

score: 12
Accepted

Test #13:

score: 12
Accepted
time: 140ms
memory: 128628kb

input:

12
100000 100000
93214 84598
93214 56491
93214 84251
93214 79335
93214 71720
93214 77307
93214 95507
93214 95410
93214 40328
93214 86071
93214 45088
93214 66766
93214 79723
93214 88378
93214 89470
93214 88357
93214 88637
93214 30576
93214 90846
93214 53961
93214 41155
93214 46341
93214 83568
93214 9...

output:

50089
0
0
0
1
50086
0
1
0
50086
50085
0
0
50088
1
50088
0
1
1
50088
50087
50088
0
50088
1
50088
1
0
50087
50086
50085
0
50087
50086
0
50088
50089
0
1
50088
1
50090
0
0
50089
1
0
1
0
50090
50089
1
1
1
1
0
50087
50088
50089
1
50087
50086
50085
50086
50087
0
1
0
50085
1
0
1
50085
1
50085
0
50085
0
0
0
...

result:

ok 100000 numbers

Test #14:

score: 12
Accepted
time: 145ms
memory: 130352kb

input:

12
100000 100000
87813 88402
87813 95508
87813 98893
87813 72683
87813 30574
87813 51137
87813 97898
87813 59020
87813 76017
87813 98656
87813 78075
87813 85721
87813 87306
87813 9176
87813 90004
87813 38369
87813 86573
87813 94026
87813 48667
87813 47642
87813 86402
87813 91112
87813 99092
87813 94...

output:

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
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
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
...

result:

ok 100000 numbers

Test #15:

score: 12
Accepted
time: 131ms
memory: 129188kb

input:

12
100000 100000
95193 86523
95193 66880
95193 88385
95193 95738
95193 64581
95193 77273
95193 81211
95193 67702
95193 37065
95193 31294
95193 98186
95193 97664
95193 91076
95193 84680
95193 90759
95193 38467
95193 97823
95193 37082
95193 89129
95193 93058
95193 52159
95193 53257
95193 95170
95193 3...

output:

1
50156
1
50156
0
50156
1
0
0
50156
50157
50158
50157
50156
50155
0
0
0
50157
1
50157
0
1
50156
1
1
0
0
0
1
1
1
50155
50156
1
50158
1
0
50155
0
0
50156
0
50156
0
50154
1
50154
50153
50154
0
0
0
50156
50155
50154
50153
50152
50151
1
0
50152
50153
50154
0
50154
0
50154
1
50154
0
0
0
50150
50151
1
0
50...

result:

ok 100000 numbers

Test #16:

score: 12
Accepted
time: 134ms
memory: 130460kb

input:

12
100000 100000
83073 96684
83073 75419
83073 71759
83073 57231
83073 99832
83073 92865
83073 92164
83073 53823
83073 31154
83073 28408
83073 88848
83073 7334
83073 98219
83073 86129
83073 95290
83073 45169
83073 95392
83073 57686
83073 61365
83073 92684
83073 51746
83073 40660
83073 95954
83073 96...

output:

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
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
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
...

result:

ok 100000 numbers

Subtask #6:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 207ms
memory: 150228kb

input:

11
100000 100000
2 29108
3 77506
4 7190
5 41884
7 9630
14 78381
15 10036
16 13569
19 80204
20 17573
24 86568
26 88304
28 91742
31 50889
32 29659
33 7909
37 61160
38 88144
40 36396
41 8142
43 20787
46 75458
48 23406
50 56495
61 74778
63 97662
70 75429
73 52031
76 49902
77 56882
81 13357
85 70152
89 3...

output:

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
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
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
...

result:

wrong answer 52775th numbers differ - expected: '0', found: '20'

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%