QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#489090#7460. rla1rmdq_FJqwqAC ✓1812ms40588kbC++143.7kb2024-07-24 17:45:042024-07-24 17:45:04

Judging History

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

  • [2024-07-24 17:45:04]
  • 评测
  • 测评结果:AC
  • 用时:1812ms
  • 内存:40588kb
  • [2024-07-24 17:45:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=2e5+5,M=500,inf=1e18;
int n,m,rt,K,a[N],pos[N],L[M],R[M],op[N],X[N],Y[N],bl,br;
int par[N],dep[N],son[N],seg[N],rev[N],top[N],siz[N],tot1,now=1,vis[N];
ll dis[N],minn,ans[N];
struct edge{int to,w;};
vector<edge>v[N];vector<int>b1,b2;
void dfs(int x,int fa){
	dep[x]=dep[fa]+1,siz[x]=1,par[x]=fa;
	for(int i=0;i<v[x].size();i++)
		if(v[x][i].to!=fa){
			dis[v[x][i].to]=dis[x]+v[x][i].w;
			dfs(v[x][i].to,x);
            siz[x]+=siz[v[x][i].to];
            if(siz[v[x][i].to]>siz[son[x]])
                son[x]=v[x][i].to;
		}
}
void dfs2(int x,int topf){
	seg[x]=++tot1;
	rev[tot1]=x;
	top[x]=topf;
	if(!son[x]) return ;
	dfs2(son[x],topf);
	for(int i=0;i<v[x].size();i++)
		if(!top[v[x][i].to])
			dfs2(v[x][i].to,v[x][i].to);
}
int get(int x,int y){
    y=max(1,dep[x]-y);
	while(dep[top[x]]>y) x=par[top[x]];
	return rev[seg[x]-(dep[x]-y)];
}
struct _FJqwq{
	int val[N],tag,sum;
	void change1(int x,int d){val[x]=d-tag;}
	void change2(int x,int d){val[x]+=d;}
	void change3(int d){tag+=d;}
	int query(int x){return val[x]+tag;}
}zhx;
void change(){
    for(int i=0,x;i<b1.size();i++){
        x=b1[i];
        a[x]=par[a[x]];
        minn=min(minn,dis[a[x]]);
        zhx.change2(x,-1);
        if(vis[a[x]]!=now){
            vis[a[x]]=now;
            b2.push_back(x);
        }
    }
    b1.clear();
	b1=b2;
	b2.clear();
}
void pushdown(){
    for(int i=bl,x;i<=br;i++){
        x=zhx.query(i);
        a[i]=get(a[i],x);
        zhx.change1(i,0);
    }
}
void pre(){
    b1.clear();
    for(int j=bl;j<=br;j++){
        minn=min(minn,dis[a[j]]);
        if((a[j]!=rt)&&(vis[par[a[j]]]!=now))
			b1.push_back(j);
        zhx.change1(j,0);
    }
}
int main(){
//	freopen("circle.in","r",stdin);
//	freopen("circle.out","w",stdout);
	scanf("%d%d%d",&n,&m,&rt),K=sqrt(n);
	for(int i=1,x,y,z;i<n;i++){
		scanf("%d%d%d",&x,&y,&z);
		v[x].push_back(edge{y,z});
		v[y].push_back(edge{x,z});
	}
    dfs(rt,0);
    dfs2(rt,rt);
    par[rt]=rt;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) pos[i]=(i-1)/K+1;
	for(int i=1;i<=n;i++) R[pos[i]]=i;
	for(int i=n;i;i--) L[pos[i]]=i;
	for(int i=1;i<=m;i++) scanf("%d%d%d",&op[i],&X[i],&Y[i]);
    for(int i=1;i<=m;i++) ans[i]=inf;
    for(int i=1;i<=pos[n];i++){
        minn=inf;bl=L[i],br=R[i];
        now++;pre();
        for(int j=1;j<=m;j++){
            if(Y[j]<bl) continue;
            if(br<X[j]) continue;
            if(op[j]==1){
                if(X[j]<=bl&&br<=Y[j]){
                    /*sigma = N*/
                     zhx.change3(1);
                     change();
                }
                else{
                    /*O(sqrt N)*/
                     pushdown();
                     for(int p=max(X[j],bl);p<=min(br,Y[j]);p++){
                         a[p]=par[a[p]];
                         minn=min(minn,dis[a[p]]);
                     }
                     pre();
                }
            }
            else{
                if(X[j]<=bl&&br<=Y[j]) /*O(1)*/ ans[j]=min(ans[j],minn);
                else{
                    /*O(sqrt N)*/
                    for(int p=max(X[j],bl),x;p<=min(br,Y[j]);p++){
				        x=zhx.query(p);
				        a[p]=get(a[p],x);
				        zhx.change1(p,0);
						ans[j]=min(ans[j],dis[a[p]]);
					}
                }
			}
        }
    }
    for(int i=1;i<=m;i++)
        if(op[i]==2)
            printf("%lld\n",ans[i]);
    return 0;
}


/*
10 17 1
1 2 154
1 3 60
3 4 156
1 5 58
5 6 112
4 7 143
7 8 57
7 9 189
7 10 197
10 10 9 4 5 1 9 2 10 3 
2 5 7
2 6 9
2 6 10
2 2 3
1 8 10
2 2 8
1 6 7
2 1 2
1 8 10
2 9 10
1 1 9
1 8 10
2 7 10
2 1 9
1 5 7
1 3 9
2 6 8

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 14188kb

input:

1000 1000 30
387 326 122462824
887 387 562582179
887 654 770128125
654 328 221541327
434 328 2553348
434 491 157302072
995 491 633483200
159 995 340185596
341 159 247406423
341 374 34719360
374 842 176004272
418 842 437086650
762 418 74356113
458 762 58888544
458 1 34594098
756 1 162123720
756 300 2...

output:

0
0
0
59618405
0
109474754
927219514
0
0
0
0
0
0
0
0
0
0
0
0
0
1121629595
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
32898230518
0
0
0
0
109474754
0
1798768018
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 531 numbers

Test #2:

score: 0
Accepted
time: 3ms
memory: 14292kb

input:

1000 1000 72
538 232 92
538 208 564
309 208 334
538 7 807
50 309 502
232 614 84
637 232 225
614 596 999
538 738 457
616 596 404
566 309 48
309 238 89
697 614 554
637 713 778
151 7 500
538 680 570
998 538 649
637 455 757
48 566 860
82 738 642
2 616 491
238 433 299
342 82 510
238 318 48
219 238 94
207...

output:

696
696
1159
0
696
0
0
0
0
1330
0
0
0
1595
0
0
0
0
696
0
0
0
696
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 457 numbers

Test #3:

score: 0
Accepted
time: 1113ms
memory: 30808kb

input:

200000 200000 6173
198188 168337 1
199878 168337 1
176719 198188 1
192955 176719 1
180639 199878 1
191536 192955 1
189369 180639 1
176719 117715 1
198188 183505 1
168337 166518 1
193620 199878 1
191536 190998 1
170250 183505 1
166518 139758 1
185126 198188 1
139758 197741 1
193620 198063 1
196236 18...

output:

0
0
0
2
2
0
3
0
1
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 99979 numbers

Test #4:

score: 0
Accepted
time: 1637ms
memory: 34300kb

input:

200000 200000 8329
190404 173256 1
190404 139279 1
178966 173256 1
178966 194546 1
194546 179636 1
178966 187886 1
187886 197598 1
187886 193440 1
143498 187886 1
194318 193440 1
199916 143498 1
149195 199916 1
149195 178505 1
198691 149195 1
178505 196502 1
198691 104714 1
198691 177305 1
177240 10...

output:

23348
23348
23346
23346
23346
23345
23346
23347
23344
23344
23344
23344
23345
23345
23345
23343
23341
23345
23346
23341
23341
23346
23335
23335
23334
23337
23339
23338
23335
23333
23333
23333
23337
23333
23336
23336
23335
23337
23338
23331
23338
23331
23330
23331
23330
23330
23329
23327
23327
23327
...

result:

ok 100295 numbers

Test #5:

score: 0
Accepted
time: 1169ms
memory: 30652kb

input:

200000 200000 21084
188105 178955 1
190655 188105 1
191517 188105 1
188105 173814 1
188105 180592 1
181783 188105 1
178955 162502 1
157871 188105 1
188623 181783 1
194914 162502 1
190655 191573 1
181783 173064 1
188105 194536 1
191517 190243 1
188105 183228 1
195145 162502 1
181783 171491 1
168262 1...

output:

4120
4120
4119
4118
4117
4118
4119
4117
4117
4115
4114
4116
4112
4112
4112
4112
4111
4107
4111
4113
4111
4107
4107
4109
4108
4107
4106
4108
4106
4106
4105
4105
4103
4103
4106
4103
4103
4104
4101
4099
4098
4098
4101
4096
4094
4094
4100
4092
4095
4091
4106
4097
4096
4091
4093
4097
4091
4103
4090
4088
...

result:

ok 100291 numbers

Test #6:

score: 0
Accepted
time: 853ms
memory: 29148kb

input:

200000 200000 195598
98825 195598 472564603
195326 195598 148190665
179136 195598 465687866
182322 195598 668538483
161178 195598 665231285
164557 195598 237353256
199026 195598 976182211
199424 195598 102216460
189354 195598 410290482
170314 195598 601542607
170253 195598 282233521
174871 195598 13...

output:

180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
180589315639
1...

result:

ok 198985 numbers

Test #7:

score: 0
Accepted
time: 745ms
memory: 29072kb

input:

200000 200000 189564
199622 189564 369725840
158674 189564 704657456
148589 189564 238609597
181464 189564 156322841
183583 189564 29858778
174113 189564 137092992
192435 189564 117708105
174914 189564 822549875
164580 189564 753621481
177082 189564 339223335
174111 189564 43202106
182554 189564 638...

output:

69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69505499669
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
69373956908
...

result:

ok 196696 numbers

Test #8:

score: 0
Accepted
time: 788ms
memory: 29152kb

input:

200000 200000 159638
191187 159638 625863988
144089 159638 341855616
193360 159638 125684629
172320 159638 353656611
171783 159638 161413264
154375 159638 20108819
199256 159638 915823059
191700 159638 388224732
185641 159638 751745496
187383 159638 476441942
141683 159638 35879066
46536 159638 8107...

output:

180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
180237323780
179628325663
179628325663
179628325663
179628325663
1...

result:

ok 196608 numbers

Test #9:

score: 0
Accepted
time: 687ms
memory: 32008kb

input:

200000 200000 157857
180089 157857 10410
153812 180089 9113
193874 153812 30243
14719 193874 17605
182997 14719 18657
172011 182997 8209
186793 172011 22264
194557 186793 5069
171500 194557 9705
114293 171500 11043
87574 114293 16582
176670 87574 9560
168832 176670 6551
168717 168832 591
185477 1687...

output:

304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
304218478
...

result:

ok 195912 numbers

Test #10:

score: 0
Accepted
time: 591ms
memory: 29288kb

input:

200000 200000 157876
165371 157876 8322
120682 165371 7802
191807 120682 16401
144738 191807 13201
133801 144738 14474
171871 133801 16651
118275 171871 21946
197590 118275 7090
157982 197590 4687
183675 157982 4172
164262 183675 736
167519 164262 18112
193961 167519 29230
180167 193961 24699
165821...

output:

207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
207144032
...

result:

ok 199032 numbers

Test #11:

score: 0
Accepted
time: 664ms
memory: 30388kb

input:

200000 200000 144312
158595 144312 22870
136773 158595 13922
199957 136773 21408
162537 199957 25980
123948 162537 32523
199095 123948 204
199708 199095 19127
136157 199708 13193
190702 136157 6062
177008 190702 9271
183614 177008 26300
195054 183614 12574
191157 195054 6273
135018 191157 20730
1873...

output:

290156147
290156147
290156147
290156147
290156147
290156147
290156147
290156147
290156147
290156147
290156147
290156147
290156147
290156147
290156147
290156147
290156147
290156147
290156147
214544995
214544995
214544995
214544995
214544995
214544995
214544995
214544995
214544995
214544995
214544995
...

result:

ok 195993 numbers

Test #12:

score: 0
Accepted
time: 1094ms
memory: 29364kb

input:

200000 200000 192380
179892 192380 784836449
197288 192380 548173142
186422 192380 674765097
126589 192380 400845214
174301 192380 171434490
175726 192380 328874410
179383 192380 261444846
176902 192380 140457714
192774 192380 256729269
196074 192380 828531480
196092 192380 751541631
93905 192380 31...

output:

2781676238886
2781676238886
2781676238886
2781676238886
2781676238886
2781676238886
2781676238886
2781676238886
2781676238886
2781676238886
2780974847208
2780974847208
2780974847208
2780974847208
2780974847208
2780974847208
2780974847208
2780974847208
2780974847208
2780213390568
2780974847208
278021...

result:

ok 192041 numbers

Test #13:

score: 0
Accepted
time: 1812ms
memory: 37236kb

input:

200000 200000 154485
191570 154485 980594532
175995 191570 427442349
186678 175995 822444069
194440 186678 348492988
178606 194440 478820422
182339 178606 163162661
166187 182339 25774399
164467 166187 601900450
167113 164467 394466605
182185 167113 816705963
172513 182185 578956732
196154 172513 17...

output:

42238775404125
42239536909624
42238775404125
42239161412201
42238712582229
42238712582229
42238032505492
42237498627910
42237498627910
42237091886401
42237091886401
42237091886401
42236191690440
42236247391953
42235710308874
42234443545848
42234443545848
42233395163856
42234929068673
42233395163856
...

result:

ok 66547 numbers

Test #14:

score: 0
Accepted
time: 790ms
memory: 29268kb

input:

200000 200000 174072
161295 174072 550840997
187792 174072 375590240
171877 174072 452047008
152632 174072 30052772
193836 174072 211687655
175731 174072 773429616
167371 174072 542113430
170965 174072 976920112
118585 174072 632910836
184703 174072 529631736
199825 174072 39102250
181199 174072 627...

output:

767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
767337576869
7...

result:

ok 196621 numbers

Test #15:

score: 0
Accepted
time: 1274ms
memory: 30568kb

input:

200000 200000 175774
185743 175774 613941869
171707 185743 72195748
192442 171707 294927032
132593 192442 541656267
182220 132593 537200060
193154 182220 809387143
179328 193154 134901963
196790 179328 576466239
188905 196790 113924622
156015 188905 654065129
141288 156015 705061815
149555 141288 68...

output:

4577977686565
4577977686565
4577977686565
4577055155303
4576921150725
4576880966500
4576880966500
4576880966500
4576921150725
4575377178042
4575233512570
4575143944363
4575357752938
4576880966500
4572245745101
4572904475283
4572245745101
4573090300994
4569260587509
4572904475283
4569260587509
456926...

result:

ok 66712 numbers

Test #16:

score: 0
Accepted
time: 1396ms
memory: 35468kb

input:

200000 200000 19748
141704 178011 62448689
153466 141704 406000526
153466 198948 239277382
110708 198948 432312839
190801 110708 93308113
189632 190801 4133198
49968 189632 172016773
49968 195374 48036858
196600 195374 291887961
196600 159556 243683716
159556 171837 12789917
171837 171225 71776765
1...

output:

22504497456931
22504497456930
22503914976053
22503263593391
22503119860190
22503119860190
22503057002069
22501904494856
22501904494856
22501837048287
22500016588081
22499535313940
22499491754782
22498936735771
22498936735771
22498358925237
22498358925237
22498358925237
22497936741053
22497936741053
...

result:

ok 99953 numbers

Test #17:

score: 0
Accepted
time: 1648ms
memory: 40588kb

input:

200000 200000 19979
185212 198405 411393815
197907 185212 821254769
197907 133192 26822693
162569 133192 13214991
143999 162569 529385289
143999 182047 494735410
194588 182047 325992535
194588 183590 216906471
183590 177348 880736896
131605 177348 425260771
131605 190543 376560298
188506 190543 6696...

output:

40070038057723
40066639490919
40064190274820
40056788070761
40047807435292
40042696657745
40029329321059
40019291516537
40019074704776
40018976048151
40008927994936
40007611799949
40007611799949
40006432193616
39995881442958
39993320342881
39990055264308
39989328905027
39965522142226
39965522142226
...

result:

ok 9910 numbers

Test #18:

score: 0
Accepted
time: 1627ms
memory: 40184kb

input:

200000 200000 24982
179150 193274 2
193274 173873 5
173873 185107 6
185107 194737 9
105494 194737 9
161515 105494 3
161515 183218 6
183218 189507 2
69064 189507 8
69064 195167 6
166530 195167 2
85320 166530 5
85320 146722 5
146722 198813 3
187396 198813 1
187396 159630 5
162817 159630 1
162817 18735...

output:

668846
668771
668750
668716
668453
668391
668334
668190
668116
668072
668050
668037
667871
667768
667614
667614
667549
667435
667364
667339
667224
667206
667191
667188
667117
667083
667018
666978
666947
666864
666704
666545
666460
666392
666386
666369
666138
666036
666036
666021
665936
665923
665866...

result:

ok 9994 numbers

Test #19:

score: 0
Accepted
time: 1466ms
memory: 37072kb

input:

200000 200000 25035
195112 166019 85
166019 193888 57
148643 193888 49
148643 86491 31
86491 120354 17
169991 120354 43
169991 178101 10
178101 191273 60
191273 176974 53
176974 158353 6
122586 158353 21
175391 122586 21
154449 175391 84
154449 161000 89
161000 185392 23
185392 89860 21
192426 89860...

output:

5069376
5069008
5068074
5067696
5065854
5065611
5063329
5063185
5062570
5062490
5062265
5061295
5061295
5061093
5060719
5060315
5060166
5059772
5058787
5056954
5055322
5054529
5053715
5052417
5051519
5049756
5046882
5045057
5042774
5041252
5034942
5032590
5032439
5032245
5029501
5029455
5028947
5028...

result:

ok 10126 numbers

Test #20:

score: 0
Accepted
time: 1544ms
memory: 38316kb

input:

200000 200000 25067
197050 171421 1
197050 186622 1
186622 185422 1
198809 185422 1
151721 198809 1
151721 184052 1
125949 184052 1
125949 197820 1
197820 198140 1
198140 180602 1
169037 180602 1
128101 169037 1
128101 171095 1
183037 171095 1
183037 189699 1
189489 189699 1
185906 189489 1
185906 1...

output:

119953
119913
119888
119883
119883
119855
119829
119795
119794
119791
119791
119753
119736
119729
119716
119711
119699
119673
119667
119658
119631
119626
119588
119583
119578
119548
119524
119508
119491
119463
119452
119435
119435
119392
119391
119389
119303
119281
119268
119248
119203
119194
119193...

result:

ok 9919 numbers