QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#139909#4891. 树上的孤独zhouhuanyi50 1609ms307372kbC++145.6kb2023-08-14 19:31:092023-08-14 19:31:10

Judging History

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

  • [2023-08-14 19:31:10]
  • 评测
  • 测评结果:50
  • 用时:1609ms
  • 内存:307372kb
  • [2023-08-14 19:31:09]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>
#define N 300000
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
struct reads
{
	int num,data;
	bool operator < (const reads &t)const
	{
		return data<t.data;
	}
};
reads tong[N+1];
struct rds
{
	int num,data,data2;
	bool operator < (const rds &t)const
	{
		return data2!=t.data2?data2<t.data2:data<t.data;
	}
};
rds tongs[N+1];
int n,m,q,ans,length,lg[N+1],rt[N+1],rt2[N+1],st[N+1],lengs,dque[N+1],top,dfn[N+1],sz[N+1],len,v1[N+1],v2[N+1],fa[N+1],fa2[N+1][21],depth[N+1],depth2[N+1];
bool used[N+1],used2[N+1];
vector<int>E[N+1];
vector<int>E2[N+1];
set<reads>s[N+1];
void add(int x,int y)
{
	E[x].push_back(y),E[y].push_back(x);
	return;
}
void add2(int x,int y)
{
	E2[x].push_back(y),E2[y].push_back(x);
	return;
}
void dfs(int x)
{
	used[x]=1;
	for (int i=0;i<E[x].size();++i)
		if (!used[E[x][i]])
			fa[E[x][i]]=x,depth[E[x][i]]=depth[x]+1,dfs(E[x][i]);
	return;
}
void dfs2(int x)
{
	dfn[x]=++len,used2[x]=sz[x]=1;
	for (int i=0;i<E2[x].size();++i)
		if (!used2[E2[x][i]])
			fa2[E2[x][i]][0]=x,depth2[E2[x][i]]=depth2[x]+1,dfs2(E2[x][i]),sz[x]+=sz[E2[x][i]];
	return;
}
bool cmp(int x,int y)
{
	return depth[x]<depth[y];
}
int lca(int x,int y)
{
	if (depth2[x]<depth2[y]) swap(x,y);
	for (int i=lg[m];i>=0;--i)
		if (depth2[fa2[x][i]]>=depth2[y])
			x=fa2[x][i];
	if (x==y) return x;
	for (int i=lg[m];i>=0;--i)
		if (fa2[x][i]!=fa2[y][i])
			x=fa2[x][i],y=fa2[y][i];
	return fa2[x][0];
}
void dfs3(int x,int d)
{
	if (depth[x]<=d) dque[++top]=v1[x];
	for (int i=0;i<E[x].size();++i)
		if (fa[E[x][i]]==x)
			dfs3(E[x][i],d);
	return;
}
struct seg
{
	struct node
	{
		int ls,rs,data;
	};
	node tree[60*N+1];
	void push_up(int k)
	{
		tree[k].data=tree[tree[k].ls].data+tree[tree[k].rs].data;
		return;
	}
	int add(int k,int L,int R,int x,int d)
	{
		int nw=++length;
		tree[nw]=tree[k];
		if (L==R)
		{
			tree[nw].data+=d;
			return nw;
		}
		int mid=(L+R)>>1;
		if (x<=mid) tree[nw].ls=add(tree[nw].ls,L,mid,x,d);
		else tree[nw].rs=add(tree[nw].rs,mid+1,R,x,d);
		push_up(nw);
		return nw;
	}
	int query(int k,int L,int R,int l,int r)
	{
		if (L==l&&R==r) return tree[k].data;
		int mid=(L+R)>>1;
		if (r<=mid) return query(tree[k].ls,L,mid,l,r);
		else if (l>=mid+1) return query(tree[k].rs,mid+1,R,l,r);
		else return query(tree[k].ls,L,mid,l,mid)+query(tree[k].rs,mid+1,R,mid+1,r);
	}
};
seg T;
struct seg2
{
	struct node
	{
		int sn[11],data;
	};
	node tree[60*N+1];
	int length;
	void push_up(int k)
	{
		tree[k].data=0;
		for (int i=1;i<=10;++i) tree[k].data+=tree[tree[k].sn[i]].data;
		return;
	}
	int add(int k,int L,int R,int x,int d)
	{
		int nw=++length;
		tree[nw]=tree[k];
		if (L==R)
		{
			tree[nw].data+=d;
			return nw;
		}
		for (int i=1;i<=10;++i)
			if (L+((R-L+1)*(i-1))/10<=x&&x<=L-1+((R-L+1)*i)/10)
			{
				if (!tree[nw].sn[i]) tree[nw].sn[i]=++length;
				tree[nw].sn[i]=add(tree[nw].sn[i],L+((R-L+1)*(i-1))/10,L-1+((R-L+1)*i)/10,x,d);
			}
		push_up(nw);
		return nw;
	}
	int query(int k,int L,int R,int l,int r)
	{
		if (L==l&&R==r) return tree[k].data;
		int sl,sr,ans=0;
		for (int i=1;i<=10;++i)
		{
			sl=L+((R-L+1)*(i-1))/10,sr=L-1+((R-L+1)*i)/10;
			if (max(sl,l)<=min(sr,r)) ans+=query(tree[k].sn[i],sl,sr,max(sl,l),min(sr,r));
		}
		return ans;
	}
};
seg2 T2;
int main()
{
	//freopen("data24.in","r",stdin);
	//freopen("tree.out","w",stdout);
	int op,x,y,d,d1,d2,ps,l,r,pv,nt;
	for (int i=2;i<=N;++i) lg[i]=lg[i>>1]+1;
	n=read(),m=read(),q=read();
	for (int i=1;i<=n-1;++i) x=read(),y=read(),add(x,y);
	for (int i=1;i<=m-1;++i) x=read(),y=read(),add2(x,y);
	for (int i=1;i<=n;++i) v1[i]=read();
	for (int i=1;i<=m;++i) v2[i]=read(),st[++lengs]=v2[i];
	sort(st+1,st+lengs+1),lengs=unique(st+1,st+lengs+1)-st-1,depth[1]=depth2[1]=1,dfs(1),dfs2(1);
	for (int i=1;i<=m;++i) tong[i]=(reads){i,depth2[i]};
	sort(tong+1,tong+m+1);
	for (int i=1;i<=lg[m];++i)
		for (int j=1;j<=m;++j)
			fa2[j][i]=fa2[fa2[j][i-1]][i-1];
	for (int i=1;i<=m;++i)
	{
		int d=lower_bound(st+1,st+lengs+1,v2[tong[i].num])-st;
		auto it=s[d].lower_bound((reads){tong[i].num,dfn[tong[i].num]});
		rt[i]=T.add(rt[i-1],1,m,dfn[tong[i].num],1);
		if (it!=s[d].end()) nt=(*it).num;
		else nt=-1;
		if (it!=s[d].begin()) it--,pv=(*it).num;
		else pv=-1;
		if (pv!=-1) rt[i]=T.add(rt[i],1,m,dfn[lca(pv,tong[i].num)],-1);
		if (nt!=-1) rt[i]=T.add(rt[i],1,m,dfn[lca(nt,tong[i].num)],-1);
		if (pv!=-1&&nt!=-1) rt[i]=T.add(rt[i],1,m,dfn[lca(pv,nt)],1);
		s[d].insert((reads){tong[i].num,dfn[tong[i].num]});
	}
	for (int i=1;i<=m;++i) tongs[i]=(rds){i,depth2[i],lower_bound(st+1,st+lengs+1,v2[i])-st};
	sort(tongs+1,tongs+m+1);
	for (int i=1;i<=m;++i) rt2[i]=T2.add(rt2[i-1],1,m,dfn[tongs[i].num],1);
	while (q--)
	{
		op=read();
		if (op==1)
		{
			x=read(),y=read(),d1=read()^ans,d2=read()^ans,ps=lower_bound(tong+1,tong+m+1,(reads){0,depth2[y]+d2+1})-tong-1,ans=T.query(rt[ps],1,m,dfn[y],dfn[y]+sz[y]-1),top=0,dfs3(x,depth[x]+d1),sort(dque+1,dque+top+1),top=unique(dque+1,dque+top+1)-dque-1;
			for (int i=1;i<=top;++i)
			{
				if (st[lower_bound(st+1,st+lengs+1,dque[i])-st]==dque[i]) d=lower_bound(st+1,st+lengs+1,dque[i])-st,l=lower_bound(tongs+1,tongs+m+1,(rds){0,0,d})-tongs,r=lower_bound(tongs+1,tongs+m+1,(rds){0,depth2[y]+d2+1,d})-tongs-1,ans+=(T2.query(rt2[r],1,m,dfn[y],dfn[y]+sz[y]-1)-T2.query(rt2[l-1],1,m,dfn[y],dfn[y]+sz[y]-1)==0);
				else ans++;
			}
			printf("%d\n",ans);
		}
		else x=read(),d=read(),v1[x]=d;
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 15ms
memory: 52760kb

input:

20 2000 2000
8 15
8 13
14 8
14 7
12 14
12 1
9 13
9 4
5 9
5 10
2 5
2 19
6 19
6 16
11 7
11 20
18 2
18 17
3 6
1395 1783
1395 1735
1735 457
457 739
739 438
438 101
101 441
441 1879
1879 1238
1238 501
501 1732
1732 1910
1910 2000
2000 834
834 917
917 111
111 780
780 1966
1966 1604
1604 623
623 1748
1748 ...

output:

105
93
2
44
19
54
192
25
69
21
21
200
78
88
137
33
68
68
54
35
24
8
23
78
59
100
27
200
40
74
97
21
87
36
197
76
28
49
11
20
55
60
24
5
109
158
23
21
15
102
36
108
26
78
171
82
32
147
145
9
136
31
109
142
119
68
34
64
18
40
56
48
54
14
35
154
111
130
144
200
21
80
84
37
73
24
28
37
160
51
62
51
95
2...

result:

ok 1481 numbers

Test #2:

score: 0
Accepted
time: 12ms
memory: 47408kb

input:

20 2000 2000
7 9
7 4
20 4
20 15
19 7
19 3
11 9
11 8
5 19
5 1
13 19
13 10
12 5
6 3
17 8
17 14
2 3
2 18
16 5
304 1166
304 1254
1254 1939
1939 430
430 1573
1573 1917
1917 934
934 226
226 1722
1722 453
453 562
562 151
151 1985
1985 1689
1689 1492
1492 108
108 948
948 753
753 92
92 1347
1347 1940
1940 10...

output:

34
197
20
99
87
35
26
19
2
36
87
19
66
199
5
156
19
35
129
62
12
199
96
19
52
4
38
198
19
200
36
60
47
64
44
172
15
48
20
166
147
53
23
46
140
48
56
77
134
39
49
200
67
19
19
40
2
19
158
24
21
79
91
45
12
126
183
20
122
29
21
28
27
65
28
58
141
25
20
172
20
3
179
7
46
141
57
57
43
150
2
86
25
8
72
2...

result:

ok 1495 numbers

Subtask #2:

score: 0
Time Limit Exceeded

Test #3:

score: 0
Time Limit Exceeded

input:

20 200000 500000
8 18
8 4
2 4
2 14
13 4
13 16
6 4
6 3
1 4
1 17
15 6
15 19
7 17
7 11
5 14
5 10
20 7
12 15
9 8
165302 77239
165302 198189
165302 180850
165302 192738
165302 173589
165302 194087
165302 191990
165302 167370
165302 101092
165302 92553
165302 163654
165302 122381
165302 152105
165302 1919...

output:

2
17595
3898
3423
16
518
5138
11355
21
7340
21
18327
15797
6638
514
1184
6110
1884
6241
662
16738
13230
1597
5446
6074
2387
6265
2
21
282
3511
1806
1236
1038
17804
4657
5536
4633
4547
21
244
2703
2
4610
8571
4037
21
13498
5648
2054
3489
4869
5828
802
2072
1482
13232
2593
938
16769
2
17623
353
5
21
7...

result:


Subtask #3:

score: 30
Accepted

Test #7:

score: 30
Accepted
time: 1087ms
memory: 167660kb

input:

20 100000 100000
16 12
16 20
6 12
6 18
2 16
2 8
5 20
5 13
3 6
3 11
19 11
19 17
9 12
9 15
4 15
4 7
10 5
14 15
14 1
85812 94626
85812 91172
91172 93788
93788 96567
96567 75524
75524 23275
23275 98340
98340 81608
81608 91480
91480 75108
75108 56605
56605 93317
93317 41617
41617 77160
77160 727
727 7559...

output:

2568
612
8337
8985
3561
9182
649
301
2478
7307
2682
1175
1401
1268
8228
4407
109
2696
640
4478
3165
9184
21
8980
2092
9950
8009
9944
21
5038
87
2038
1881
19
1292
2183
336
1101
9386
3477
7723
1958
2741
1256
2331
715
21
545
21
448
699
2332
447
18
38
1424
2321
693
2459
21
2320
714
9999
8
196
1366
8933
...

result:

ok 74842 numbers

Test #8:

score: 0
Accepted
time: 1012ms
memory: 168568kb

input:

20 100000 100000
6 12
6 15
20 12
20 5
9 15
9 14
2 20
2 19
7 5
7 4
3 20
3 16
10 7
10 8
18 20
18 1
13 4
13 11
17 13
76027 68976
76027 57693
57693 93102
93102 28171
28171 85749
85749 99702
99702 83297
83297 72320
72320 89998
89998 69676
69676 84244
84244 44418
44418 78575
78575 4284
4284 99851
99851 90...

output:

1821
2139
1444
3155
8443
9995
2539
27
64
3274
2129
2
259
2719
152
3900
6031
5006
6290
879
1083
6041
496
6004
670
6
1451
1405
7249
977
9500
402
1104
1444
2795
2267
1171
1971
2886
5045
3
2699
765
3885
241
21
2683
1746
1756
7401
1111
4371
1107
1025
1369
1455
1420
2128
2165
6077
2793
1825
1263
2042
136
...

result:

ok 74861 numbers

Test #9:

score: 0
Accepted
time: 976ms
memory: 166776kb

input:

20 100000 100000
16 17
16 12
15 16
15 8
1 12
1 9
2 15
2 13
7 12
7 5
11 2
11 19
3 8
3 6
4 15
10 17
10 18
14 13
14 20
67546 88879
67546 89198
89198 92647
92647 60049
60049 72475
72475 67403
67403 26140
26140 9738
9738 85753
85753 31691
31691 30604
30604 84416
84416 92592
92592 96710
96710 84006
84006 ...

output:

3320
1811
2176
1515
9571
9829
2737
1223
1728
9815
9933
897
151
272
300
6209
7663
673
1113
918
2190
1241
1106
9988
4
7359
2882
2299
3278
3088
503
3767
1274
2
2160
4738
4304
184
75
2238
3879
192
9987
2744
1320
4089
2428
2759
740
2689
9306
85
3841
1510
3091
3
9327
3677
3221
4692
9315
7211
1780
9997
170...

result:

ok 74827 numbers

Test #10:

score: 0
Accepted
time: 1011ms
memory: 169620kb

input:

20 100000 100000
2 3
2 6
17 2
17 10
5 2
5 9
20 10
20 18
7 2
7 16
13 2
13 8
4 10
4 14
11 17
11 15
19 10
19 12
1 11
85514 99510
85514 84831
85514 68620
85514 48208
85514 42479
85514 71645
85514 80596
85514 88493
85514 99514
85514 31378
85514 80504
85514 81861
85514 94839
85514 69330
85514 40591
85514 ...

output:

2
1716
3641
9997
3794
1209
3165
2597
1563
8595
463
4162
893
3028
435
8705
6861
1923
2814
2796
20
2363
1933
1893
762
673
13
7862
2839
2008
2985
2779
9993
2480
3
3712
9951
113
1062
9981
2059
697
3
109
2045
7767
861
149
70
9999
928
21
1017
2082
111
3375
242
1095
3325
880
3574
538
1954
20
376
1434
3507
...

result:

ok 74851 numbers

Test #11:

score: 0
Accepted
time: 1033ms
memory: 167104kb

input:

20 100000 100000
12 10
12 5
17 5
14 10
14 8
9 8
9 13
16 12
16 19
6 8
6 3
18 19
18 15
1 12
1 7
20 19
20 4
2 12
11 4
34733 89384
34733 80376
80376 95740
95740 97840
97840 69394
69394 38211
38211 59175
59175 97280
97280 76697
76697 84307
84307 75221
75221 94161
94161 57166
57166 84005
84005 75107
75107...

output:

2486
7650
3313
2
7109
665
5733
1639
3748
5026
3376
3356
4964
9976
4326
982
2015
90
250
1631
3294
625
6789
7678
10000
653
3152
3312
3102
21
7581
2202
230
21
133
9852
3458
21
1652
5963
8692
2
121
3913
1395
3458
7411
3857
1934
355
3
3083
3213
9957
3132
281
8830
1462
6288
2980
1317
1648
897
1353
3303
19...

result:

ok 74832 numbers

Test #12:

score: 0
Accepted
time: 1122ms
memory: 167728kb

input:

20 100000 100000
6 8
6 5
9 5
9 11
16 5
16 10
13 8
13 18
20 11
20 4
1 8
1 15
12 5
12 14
7 11
3 13
3 17
19 15
2 10
95202 70596
95202 63084
63084 80990
80990 97264
97264 75236
75236 76413
76413 21787
21787 79077
79077 23111
23111 87359
87359 12982
12982 71974
71974 94809
94809 78084
78084 89131
89131 9...

output:

3795
833
1450
8881
944
1103
4920
6523
2458
3126
642
4493
2278
300
3728
1304
155
474
99
6044
1871
2030
1058
2494
1320
1114
9563
853
1303
3571
377
5761
4259
1225
1700
705
24
1825
3684
2056
2800
9144
3778
1773
61
13
6935
44
9555
5851
2059
1639
3055
1632
2845
9999
9955
1577
610
587
3685
3517
865
66
1521...

result:

ok 74853 numbers

Subtask #4:

score: 10
Accepted

Test #13:

score: 10
Accepted
time: 1609ms
memory: 307372kb

input:

1 200000 500000
189127 137023
189127 199761
199761 160701
160701 130639
130639 190908
190908 176819
176819 193363
193363 188021
188021 182446
182446 186028
186028 198828
198828 190792
190792 155378
155378 189428
189428 177276
177276 146159
146159 175923
175923 188073
188073 182206
182206 131072
1310...

output:

3782
1773
771
7328
18160
19394
1952
2
5498
2
2859
3368
7393
5131
5706
2
6001
19866
2
5123
2
12549
1497
4837
7770
16333
18175
5926
17983
19707
3821
17709
17094
4226
3822
576
5637
3660
4987
15686
2
18774
29
5068
16606
2276
16601
4544
598
845
19976
7054
882
164
2744
1683
6747
5091
1632
5137
2931
2778
1...

result:

ok 374196 numbers

Test #14:

score: 0
Accepted
time: 1525ms
memory: 306280kb

input:

1 200000 500000
180482 179464
180482 193543
193543 198371
198371 169074
169074 164609
164609 168204
168204 197371
197371 173986
173986 182584
182584 173674
173674 181375
181375 190105
190105 186309
186309 189847
189847 168603
168603 99409
99409 185327
185327 172756
172756 99406
99406 185574
185574 1...

output:

10673
5634
7391
680
6687
12592
2003
4840
35
6181
17198
1362
3085
13905
1102
2869
1275
5446
4861
5644
2008
1518
20000
465
5127
2653
19817
779
2971
3892
5484
6267
1930
4344
263
789
7078
1447
2092
4322
3092
856
11362
19716
1105
2284
8702
4125
14956
11052
2786
4142
3437
9702
5492
3024
613
1707
16541
610...

result:

ok 374199 numbers

Subtask #5:

score: 0
Time Limit Exceeded

Test #15:

score: 0
Time Limit Exceeded

input:

20 200000 1000000
13 10
13 5
19 5
19 20
15 10
15 6
12 6
12 3
8 10
8 2
1 20
1 11
14 10
14 16
18 3
18 7
4 3
9 10
9 17
194055 154514
194055 148156
148156 115271
115271 198116
198116 179433
179433 171975
171975 196600
196600 167194
167194 185078
185078 191409
191409 163496
163496 178243
178243 154093
15...

output:

459
5817
10120
7654
4894
19469
3577
16028
2835
7538
1131
9925
18495
497
11876
2132
9849
7576
7278
111
1850
7391
3350
6100
19488
16462
6207
1725
5922
5596
3820
1918
718
3319
2715
19890
5606
634
753
1301
15995
2973
1671
14675
5218
2639
118
1896
3266
1935
14603
4577
7219
5902
11027
4392
7461
9754
19632...

result: