QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549139#3279. 经典游戏Flamire#31 185ms153712kbC++172.4kb2024-09-06 10:09:062024-09-06 10:09:08

Judging History

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

  • [2024-09-06 10:09:08]
  • 评测
  • 测评结果:31
  • 用时:185ms
  • 内存:153712kb
  • [2024-09-06 10:09:06]
  • 提交

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)
{
	for(int i=19;~i;--i)
	{
		++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)
{
	for(int i=19;~i;--i)
	{
		if(!--cnt[x])gb[++gb[0]]=x;
		x=ch[x][v>>i&1];
	}
	if(!--cnt[x])gb[++gb[0]]=x;
}
int search(int x,int tag,int v)
{
	int ans=0;
	for(int i=19;~i;--i)
	{
		if(v>>i&1)ans+=cnt[ch[x][((v^tag)>>i&1)^1]];
		x=ch[x][(v^tag)>>i&1];
	}
	ans+=cnt[x];
	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)
{
	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]));
}
bool check(int 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);
	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;
	if(D&1)
	{
		Cu=C,Cv=fa[C];
		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)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;
		for(int z:G[y])ans+=check(z);
		ans+=check(y);
		printf("%d\n",cnt-ans);
	}
	fclose(stdin);fclose(stdout);return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 16
Accepted

Test #1:

score: 16
Accepted
time: 59ms
memory: 122808kb

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: 60ms
memory: 122472kb

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: 59ms
memory: 121708kb

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: 52ms
memory: 121508kb

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: 64ms
memory: 123416kb

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: 60ms
memory: 122616kb

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:

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

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 185ms
memory: 153712kb

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:

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

result:

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

Subtask #5:

score: 0
Time Limit Exceeded

Test #13:

score: 0
Time Limit Exceeded

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:

99998
1
1
1
1
99993
1
1
1
99989
99988
1
1
99985
1
99983
1
1
1
99979
99978
99977
1
99975
1
99973
1
1
99970
99969
99968
1
99966
99965
1
99963
99962
1
1
99959
1
99957
1
1
99954
1
1
1
1
99949
99948
1
1
1
1
1
99942
99941
99940
1
99938
99937
99936
99935
99934
1
1
1
99930
1
1
1
99926
1
99924
1
99922
1
1
1
...

result:


Subtask #6:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 180ms
memory: 141708kb

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:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
...

result:

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

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%