QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#510521#4891. 树上的孤独ANIG30 1608ms200028kbC++143.9kb2024-08-09 08:21:062024-08-09 08:21:07

Judging History

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

  • [2024-08-09 08:21:07]
  • 评测
  • 测评结果:30
  • 用时:1608ms
  • 内存:200028kb
  • [2024-08-09 08:21:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2.1e5+5;
namespace tr{
    struct node{
    	signed lson,rson,sm;
    }p[N*400];
    int idx;
    void upset(int x){
    	p[x].sm=p[p[x].lson].sm+p[p[x].rson].sm;
    }
    void add(int x,int y,int d,int sm,int nl,int nr){
    	if(nl==nr){
    		p[y].sm=p[x].sm+sm;
    		return;
    	}
    	int mid=nl+nr>>1;
    	if(d<=mid){
    		p[y].rson=p[x].rson;
    		p[y].lson=++idx;
    		add(p[x].lson,idx,d,sm,nl,mid);
    	}else{
    		p[y].lson=p[x].lson;
    		p[y].rson=++idx;
    		add(p[x].rson,idx,d,sm,mid+1,nr);
    	}
    	upset(y);
    }
    int gets(int x,int l,int r,int nl,int nr){
    	if(!x)return 0;
    	if(l<=nl&&r>=nr)return p[x].sm;
    	int mid=nl+nr>>1;
    	if(r<=mid)return gets(p[x].lson,l,r,nl,mid);
    	if(l>mid)return gets(p[x].rson,l,r,mid+1,nr);
    	return gets(p[x].lson,l,r,nl,mid)+gets(p[x].rson,l,r,mid+1,nr);
    }
}
int n,m,qs,ans,mk[N],zx[N],bk[N],rt[N],siz[N],rs[N],w1[N],w2[N],mx,dfn1[N],dfn2[N],eds1[N],eds2[N],dy1[N],dy2[N],dep1[N],dep2[N],idx1,idx2;
vector<int>e[N],p[N],jl,g[N];
void dfs1(int x){
	mk[x]=1;dfn1[x]=++idx1;
	dy1[idx1]=x;
	for(auto c:e[x]){
		if(mk[c])continue;
		dep1[c]=dep1[x]+1;
		dfs1(c);
	}
	eds1[x]=idx1;
	mk[x]=0;
}
void dfs2(int x){
	mk[x]=1;dfn2[x]=++idx2;
	dy2[idx2]=x;
	for(auto c:p[x]){
		if(mk[c])continue;
		dep2[c]=dep2[x]+1;
		dfs2(c);
	}
	eds2[x]=idx2;
	mk[x]=0;
}
bool cmp(int a,int b){
	if(mk[a]!=mk[b])return mk[a]>mk[b];
	return siz[a]<siz[b];
}
void dfs(int x){
	mk[x]=1;
	siz[x]=1;
	for(auto c:p[x]){
		if(mk[c])continue;
		dfs(c);
		siz[x]+=siz[c];
	}
	sort(p[x].begin(),p[x].end(),cmp);
	mk[x]=0;
}
void clr(){
	while(jl.size())zx[jl.back()]=m,jl.pop_back();
}
void add(int &x,int l,int r,int sm){
//	cout<<l<<" "<<r<<" "<<sm<<endl;
	int tmp=++tr::idx;
	tr::add(x,tmp,l,sm,0,m);
	x=tmp;
	tmp=++tr::idx;
	tr::add(x,tmp,r+1,-sm,0,m);
	x=tmp;
}
void add(int x,int&y){
//	cout<<"add"<<x<<endl;
	jl.push_back(w2[x]);
	if(dep2[x]<zx[w2[x]])add(y,dep2[x],zx[w2[x]]-1,1),zx[w2[x]]=dep2[x];
}
void dfs3(int x,int&y){
	bk[x]=1;add(x,y);
	for(auto c:p[x]){
		if(bk[c]||mk[c])continue;
		dfs3(c,y);
	}
	bk[x]=0;
}
void solve(int x){
	mk[x]=1;
	for(auto c:p[x]){
		if(mk[c])continue;
		clr();
		solve(c);
	}
	if(!mk[p[x].back()])rt[x]=rt[p[x].back()];
	else rt[x]=++tr::idx;
//	cout<<x<<" "<<p[x].back()<<endl;
	add(x,rt[x]);
	for(int i=0;i<p[x].size()-1;i++){
		int c=p[x][i];
		if(mk[c])continue;
		dfs3(c,rt[x]);
	}
	mk[x]=0;
}
signed main(){
//	freopen("in.txt","r",stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m>>qs;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	for(int i=1;i<m;i++){
		int x,y;
		cin>>x>>y;
		p[x].push_back(y);
		p[y].push_back(x);
	}
	for(int i=1;i<=n;i++)cin>>w1[i],jl.push_back(w1[i]);
	for(int i=1;i<=m;i++)cin>>w2[i],jl.push_back(w2[i]);
	sort(jl.begin(),jl.end());
	jl.resize(unique(jl.begin(),jl.end())-jl.begin());
	mx=jl.size();
	for(int i=1;i<=n;i++)w1[i]=lower_bound(jl.begin(),jl.end(),w1[i])-jl.begin()+1;
	for(int i=1;i<=m;i++)w2[i]=lower_bound(jl.begin(),jl.end(),w2[i])-jl.begin()+1;
	for(int i=1;i<=mx;i++)zx[i]=m;
	jl.clear();
	dfs1(1);
	dfs2(1);
	dfs(1);
	solve(1);
	for(int i=1;i<=m;i++)g[w2[dy2[i]]].push_back(i);
	while(qs--){
		int x,y,a,b,op;
		cin>>op>>x>>y;
		if(op==1){
			cin>>a>>b;
			a^=ans;b^=ans;
			int res=tr::gets(rt[y],0,min(dep2[y]+b,m-1),0,m);
			set<int>q;
			for(int i=dfn1[x];i<=eds1[x];i++){
				int c=w1[dy1[i]];
				if(dep1[dy1[i]]-dep1[x]>a)continue;
				if(q.count(c))continue;
				q.insert(c);
				int oks=1;
				for(auto d:g[c]){
					if(d>=dfn2[y]&&d<=eds2[y]&&dep2[dy2[d]]-dep2[y]<=b)oks=0;
				}
				if(oks)res++;
			}
			cout<<(ans=res)<<"\n";
		}else{
			w1[x]=y;
		}
	}
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 4ms
memory: 42444kb

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: 10
Accepted
time: 6ms
memory: 45192kb

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: 20
Accepted

Test #3:

score: 20
Accepted
time: 789ms
memory: 181828kb

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:

ok 500000 numbers

Test #4:

score: 20
Accepted
time: 760ms
memory: 183404kb

input:

20 200000 500000
11 2
11 1
17 1
17 6
10 2
10 16
20 6
20 15
12 1
12 4
9 16
9 3
7 1
13 15
8 15
8 5
18 7
18 14
19 12
146231 199607
146231 196481
196481 194263
194263 192044
192044 169873
169873 141903
141903 129271
129271 176167
176167 170198
170198 173775
173775 174130
174130 184691
184691 198900
1989...

output:

933
12179
2009
2889
5129
7229
2884
5588
1070
21
2789
2194
654
2643
7840
3203
3946
105
1626
4635
775
2
14
6001
18249
18326
2
1386
3505
11361
1254
4501
5630
21
12011
1392
2902
5252
7857
4
1038
1796
3342
129
19959
18597
1924
116
104
1603
3593
4365
3967
921
1007
2344
4728
3051
2048
4607
4563
1648
8059
3...

result:

ok 500000 numbers

Test #5:

score: 20
Accepted
time: 823ms
memory: 194752kb

input:

20 200000 500000
11 19
11 12
6 12
6 8
20 19
20 7
1 6
1 2
9 11
9 10
15 6
15 17
3 7
3 14
13 19
4 13
4 18
5 6
5 16
164001 91176
164001 174000
174000 170154
170154 69790
69790 174420
174420 193462
193462 149823
149823 188081
188081 127489
127489 191901
191901 194376
194376 197936
197936 185448
185448 19...

output:

5329
19807
5406
4355
2
1453
3216
21
2758
2561
387
8122
6615
4577
6108
2
2224
586
2950
19824
3119
6437
4852
5552
17244
7466
5462
2909
9992
19918
6653
19811
448
1026
1467
424
21
3056
1866
4262
9943
6499
3180
3688
6479
5096
6369
21
232
1765
2369
1789
1942
1141
3690
8680
7346
5265
21
16599
701
4354
1413...

result:

ok 500000 numbers

Test #6:

score: 20
Accepted
time: 815ms
memory: 200028kb

input:

20 200000 500000
17 5
17 11
18 5
18 14
1 17
1 3
16 18
16 13
7 16
7 15
9 15
9 4
12 11
12 2
20 14
20 19
8 9
8 10
6 17
166750 113956
166750 160259
160259 143147
143147 172478
172478 173006
173006 89817
89817 196218
196218 191942
191942 193748
193748 177077
177077 157435
157435 125058
125058 164374
1643...

output:

2490
7164
1575
19999
2452
1702
26
21
5118
19981
10942
21
21
19266
1523
13
21
6341
21
1040
581
1643
7021
16863
7376
1626
1211
1982
21
15029
10542
14571
135
21
1001
21
1390
4982
2928
1539
5422
1095
2923
4872
1377
19997
14571
7196
4640
1988
1707
5216
5742
17354
12204
1941
17445
516
21
13
14682
19992
21...

result:

ok 500000 numbers

Subtask #3:

score: 0
Wrong Answer

Test #7:

score: 30
Accepted
time: 218ms
memory: 115116kb

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
Wrong Answer
time: 229ms
memory: 115820kb

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
8444
9996
2539
27
64
3274
2129
2
259
2720
152
3900
6031
5006
6292
879
1082
6041
496
6004
670
6
1451
1405
7249
977
9500
403
1104
1443
2796
2269
1173
1972
2885
5041
3
2699
765
3886
242
21
2682
1749
1756
7399
1113
4375
1107
1025
1369
1455
1420
2129
2162
6077
2792
1827
1263
2042
136
...

result:

wrong answer 5th numbers differ - expected: '8443', found: '8444'

Subtask #4:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 460ms
memory: 186712kb

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:

3781
1773
771
7329
18160
19394
1952
2
5499
2
2858
3368
7393
5130
5707
2
6002
19866
2
5124
2
12549
1497
4837
7770
16334
18175
5925
17983
19707
3821
17710
17092
4226
3822
576
5638
3660
4988
15687
2
18774
29
5068
16605
2276
16601
4544
598
845
19976
7055
882
164
2743
1683
6747
5091
1632
5137
2930
2778
1...

result:

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

Subtask #5:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 1608ms
memory: 185708kb

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
11875
2131
9849
7577
7278
111
1851
7390
3350
6102
19488
16465
6207
1725
5922
5595
3820
1917
718
3316
2714
19890
5606
635
753
1301
15995
2974
1672
14671
5218
2639
118
1896
3266
1935
14605
4577
7219
5906
11035
4392
7460
9754
19632...

result:

wrong answer 15th numbers differ - expected: '11876', found: '11875'