#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
const int maxn=200000+10;
vector<int>adj[maxn];
int q,high[maxn],n,mod,timea=0,part[maxn];
pair<int,int>stf[maxn];
struct segment{
vector<long long>seg;
int sz=0;
void create(){
while(__builtin_popcount(sz)!=1){
sz++;
}
seg.resize(sz*2,1);
}
void add(int i,int l,int r,int tl,int tr,int w){
if(l>r||l>tr||r<tl||tl>tr){
return ;
}
if(l>=tl&&r<=tr){
seg[i]*=w;
seg[i]%=mod;
return ;
}
int m=(l+r)>>1;
add((i<<1),l,m,tl,tr,w);
add((i<<1)^1,m+1,r,tl,tr,w);
return ;
}
int pors(int i){
if(i==0){
return 1;
}
int ret=seg[i]*pors((i>>1))%mod;
return ret;
}
}seg[maxn];
vector<pair<int,int>>alll[maxn];
void pre(int u=1,int par=1){
part[u]=par;
timea++;
stf[u].first=timea;
alll[high[u]].push_back(make_pair(stf[u].first,u));
for(auto x:adj[u]){
if(x!=par){
high[x]=high[u]+1;
pre(x,u);
}
}
stf[u].second=timea;
}
void upd(int u,int dis,int w){
int z=0;
int lev=high[u]+dis;
while(lev>=0&&high[u]<=lev){
if(lev<maxn){
int l=lower_bound(alll[lev].begin(),alll[lev].end(),make_pair(stf[u].first,-1))-alll[lev].begin();
int r=lower_bound(alll[lev].begin(),alll[lev].end(),make_pair(stf[u].second+1,-1))-alll[lev].begin();
r--;
seg[lev].add(1,0,seg[lev].sz-1,l,r,w);
}
if(z==1){
u=part[u];
lev--;
z=0;
}
else{
lev--;
z=1;
}
}
}
void solve(int u){
int ind=lower_bound(alll[high[u]].begin(),alll[high[u]].end(),make_pair(stf[u].first,u))-alll[high[u]].begin();
cout<<seg[high[u]].pors(ind+seg[high[u]].sz)<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>mod;
for(int i=0;i<n-1;i++){
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
pre(1);
for(int i=0;i<maxn;i++){
seg[i].sz=alll[i].size();
seg[i].create();
}
for(int i=1;i<=n;i++){
int d;
cin>>d;
upd(i,0,d);
}
cin>>q;
for(int i=0;i<q;i++){
int qq;
cin>>qq;
if(qq==1){
int u,d,w;
cin>>u>>d>>w;
if(d>40){
assert(0);
}
upd(u,d,w);
}
else{
int u;
cin>>u;
solve(u);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
25388 KB |
Output is correct |
2 |
Correct |
13 ms |
25436 KB |
Output is correct |
3 |
Correct |
15 ms |
25440 KB |
Output is correct |
4 |
Correct |
15 ms |
25436 KB |
Output is correct |
5 |
Correct |
15 ms |
25436 KB |
Output is correct |
6 |
Correct |
15 ms |
25688 KB |
Output is correct |
7 |
Correct |
15 ms |
25608 KB |
Output is correct |
8 |
Correct |
14 ms |
25436 KB |
Output is correct |
9 |
Correct |
14 ms |
25528 KB |
Output is correct |
10 |
Correct |
14 ms |
25352 KB |
Output is correct |
11 |
Correct |
14 ms |
25436 KB |
Output is correct |
12 |
Correct |
13 ms |
25436 KB |
Output is correct |
13 |
Correct |
14 ms |
25348 KB |
Output is correct |
14 |
Correct |
15 ms |
25676 KB |
Output is correct |
15 |
Correct |
15 ms |
25388 KB |
Output is correct |
16 |
Correct |
14 ms |
25436 KB |
Output is correct |
17 |
Correct |
15 ms |
25356 KB |
Output is correct |
18 |
Correct |
14 ms |
25436 KB |
Output is correct |
19 |
Correct |
17 ms |
25432 KB |
Output is correct |
20 |
Correct |
14 ms |
25368 KB |
Output is correct |
21 |
Correct |
14 ms |
25436 KB |
Output is correct |
22 |
Correct |
14 ms |
25296 KB |
Output is correct |
23 |
Correct |
14 ms |
25436 KB |
Output is correct |
24 |
Correct |
14 ms |
25436 KB |
Output is correct |
25 |
Correct |
14 ms |
25472 KB |
Output is correct |
26 |
Correct |
14 ms |
25436 KB |
Output is correct |
27 |
Correct |
14 ms |
25500 KB |
Output is correct |
28 |
Correct |
14 ms |
25644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
25432 KB |
Output is correct |
2 |
Correct |
294 ms |
46516 KB |
Output is correct |
3 |
Correct |
445 ms |
45396 KB |
Output is correct |
4 |
Correct |
290 ms |
55892 KB |
Output is correct |
5 |
Correct |
346 ms |
46080 KB |
Output is correct |
6 |
Correct |
394 ms |
45268 KB |
Output is correct |
7 |
Correct |
416 ms |
45388 KB |
Output is correct |
8 |
Correct |
369 ms |
45372 KB |
Output is correct |
9 |
Correct |
314 ms |
64044 KB |
Output is correct |
10 |
Correct |
338 ms |
61144 KB |
Output is correct |
11 |
Correct |
295 ms |
46416 KB |
Output is correct |
12 |
Correct |
454 ms |
45344 KB |
Output is correct |
13 |
Correct |
319 ms |
45204 KB |
Output is correct |
14 |
Correct |
381 ms |
45860 KB |
Output is correct |
15 |
Correct |
394 ms |
45024 KB |
Output is correct |
16 |
Correct |
404 ms |
45152 KB |
Output is correct |
17 |
Correct |
411 ms |
45476 KB |
Output is correct |
18 |
Correct |
14 ms |
25436 KB |
Output is correct |
19 |
Correct |
14 ms |
25288 KB |
Output is correct |
20 |
Correct |
15 ms |
25500 KB |
Output is correct |
21 |
Correct |
14 ms |
25436 KB |
Output is correct |
22 |
Correct |
14 ms |
25332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
25432 KB |
Output is correct |
2 |
Correct |
294 ms |
46516 KB |
Output is correct |
3 |
Correct |
445 ms |
45396 KB |
Output is correct |
4 |
Correct |
290 ms |
55892 KB |
Output is correct |
5 |
Correct |
346 ms |
46080 KB |
Output is correct |
6 |
Correct |
394 ms |
45268 KB |
Output is correct |
7 |
Correct |
416 ms |
45388 KB |
Output is correct |
8 |
Correct |
369 ms |
45372 KB |
Output is correct |
9 |
Correct |
314 ms |
64044 KB |
Output is correct |
10 |
Correct |
338 ms |
61144 KB |
Output is correct |
11 |
Correct |
295 ms |
46416 KB |
Output is correct |
12 |
Correct |
454 ms |
45344 KB |
Output is correct |
13 |
Correct |
319 ms |
45204 KB |
Output is correct |
14 |
Correct |
381 ms |
45860 KB |
Output is correct |
15 |
Correct |
394 ms |
45024 KB |
Output is correct |
16 |
Correct |
404 ms |
45152 KB |
Output is correct |
17 |
Correct |
411 ms |
45476 KB |
Output is correct |
18 |
Correct |
14 ms |
25436 KB |
Output is correct |
19 |
Correct |
14 ms |
25288 KB |
Output is correct |
20 |
Correct |
15 ms |
25500 KB |
Output is correct |
21 |
Correct |
14 ms |
25436 KB |
Output is correct |
22 |
Correct |
14 ms |
25332 KB |
Output is correct |
23 |
Correct |
14 ms |
25436 KB |
Output is correct |
24 |
Correct |
310 ms |
46272 KB |
Output is correct |
25 |
Correct |
648 ms |
45244 KB |
Output is correct |
26 |
Correct |
354 ms |
62708 KB |
Output is correct |
27 |
Correct |
376 ms |
45980 KB |
Output is correct |
28 |
Correct |
465 ms |
45888 KB |
Output is correct |
29 |
Correct |
471 ms |
45812 KB |
Output is correct |
30 |
Correct |
362 ms |
45556 KB |
Output is correct |
31 |
Correct |
311 ms |
57744 KB |
Output is correct |
32 |
Correct |
333 ms |
60772 KB |
Output is correct |
33 |
Correct |
287 ms |
46672 KB |
Output is correct |
34 |
Correct |
563 ms |
45132 KB |
Output is correct |
35 |
Correct |
16 ms |
25432 KB |
Output is correct |
36 |
Correct |
14 ms |
25436 KB |
Output is correct |
37 |
Correct |
15 ms |
25432 KB |
Output is correct |
38 |
Correct |
14 ms |
25480 KB |
Output is correct |
39 |
Correct |
14 ms |
25688 KB |
Output is correct |
40 |
Correct |
14 ms |
25436 KB |
Output is correct |
41 |
Correct |
15 ms |
25396 KB |
Output is correct |
42 |
Correct |
15 ms |
25460 KB |
Output is correct |
43 |
Correct |
14 ms |
25520 KB |
Output is correct |
44 |
Correct |
14 ms |
25396 KB |
Output is correct |
45 |
Correct |
14 ms |
25432 KB |
Output is correct |
46 |
Correct |
14 ms |
25436 KB |
Output is correct |
47 |
Correct |
14 ms |
25436 KB |
Output is correct |
48 |
Correct |
14 ms |
25436 KB |
Output is correct |
49 |
Correct |
16 ms |
25688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
25360 KB |
Output is correct |
2 |
Correct |
378 ms |
60916 KB |
Output is correct |
3 |
Correct |
889 ms |
55888 KB |
Output is correct |
4 |
Correct |
492 ms |
57044 KB |
Output is correct |
5 |
Correct |
1774 ms |
43744 KB |
Output is correct |
6 |
Correct |
1195 ms |
43240 KB |
Output is correct |
7 |
Correct |
740 ms |
43836 KB |
Output is correct |
8 |
Correct |
306 ms |
43092 KB |
Output is correct |
9 |
Correct |
356 ms |
54828 KB |
Output is correct |
10 |
Correct |
936 ms |
59352 KB |
Output is correct |
11 |
Correct |
802 ms |
43908 KB |
Output is correct |
12 |
Execution timed out |
4019 ms |
43296 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
25432 KB |
Output is correct |
2 |
Correct |
365 ms |
56508 KB |
Output is correct |
3 |
Correct |
1020 ms |
51300 KB |
Output is correct |
4 |
Correct |
523 ms |
54376 KB |
Output is correct |
5 |
Correct |
1633 ms |
45312 KB |
Output is correct |
6 |
Correct |
1074 ms |
45168 KB |
Output is correct |
7 |
Correct |
781 ms |
44256 KB |
Output is correct |
8 |
Correct |
306 ms |
44160 KB |
Output is correct |
9 |
Correct |
372 ms |
62148 KB |
Output is correct |
10 |
Correct |
906 ms |
59992 KB |
Output is correct |
11 |
Correct |
829 ms |
46192 KB |
Output is correct |
12 |
Execution timed out |
4022 ms |
43572 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
25388 KB |
Output is correct |
2 |
Correct |
13 ms |
25436 KB |
Output is correct |
3 |
Correct |
15 ms |
25440 KB |
Output is correct |
4 |
Correct |
15 ms |
25436 KB |
Output is correct |
5 |
Correct |
15 ms |
25436 KB |
Output is correct |
6 |
Correct |
15 ms |
25688 KB |
Output is correct |
7 |
Correct |
15 ms |
25608 KB |
Output is correct |
8 |
Correct |
14 ms |
25436 KB |
Output is correct |
9 |
Correct |
14 ms |
25528 KB |
Output is correct |
10 |
Correct |
14 ms |
25352 KB |
Output is correct |
11 |
Correct |
14 ms |
25436 KB |
Output is correct |
12 |
Correct |
13 ms |
25436 KB |
Output is correct |
13 |
Correct |
14 ms |
25348 KB |
Output is correct |
14 |
Correct |
15 ms |
25676 KB |
Output is correct |
15 |
Correct |
15 ms |
25388 KB |
Output is correct |
16 |
Correct |
14 ms |
25436 KB |
Output is correct |
17 |
Correct |
15 ms |
25356 KB |
Output is correct |
18 |
Correct |
14 ms |
25436 KB |
Output is correct |
19 |
Correct |
17 ms |
25432 KB |
Output is correct |
20 |
Correct |
14 ms |
25368 KB |
Output is correct |
21 |
Correct |
14 ms |
25436 KB |
Output is correct |
22 |
Correct |
14 ms |
25296 KB |
Output is correct |
23 |
Correct |
14 ms |
25436 KB |
Output is correct |
24 |
Correct |
14 ms |
25436 KB |
Output is correct |
25 |
Correct |
14 ms |
25472 KB |
Output is correct |
26 |
Correct |
14 ms |
25436 KB |
Output is correct |
27 |
Correct |
14 ms |
25500 KB |
Output is correct |
28 |
Correct |
14 ms |
25644 KB |
Output is correct |
29 |
Correct |
13 ms |
25432 KB |
Output is correct |
30 |
Correct |
294 ms |
46516 KB |
Output is correct |
31 |
Correct |
445 ms |
45396 KB |
Output is correct |
32 |
Correct |
290 ms |
55892 KB |
Output is correct |
33 |
Correct |
346 ms |
46080 KB |
Output is correct |
34 |
Correct |
394 ms |
45268 KB |
Output is correct |
35 |
Correct |
416 ms |
45388 KB |
Output is correct |
36 |
Correct |
369 ms |
45372 KB |
Output is correct |
37 |
Correct |
314 ms |
64044 KB |
Output is correct |
38 |
Correct |
338 ms |
61144 KB |
Output is correct |
39 |
Correct |
295 ms |
46416 KB |
Output is correct |
40 |
Correct |
454 ms |
45344 KB |
Output is correct |
41 |
Correct |
319 ms |
45204 KB |
Output is correct |
42 |
Correct |
381 ms |
45860 KB |
Output is correct |
43 |
Correct |
394 ms |
45024 KB |
Output is correct |
44 |
Correct |
404 ms |
45152 KB |
Output is correct |
45 |
Correct |
411 ms |
45476 KB |
Output is correct |
46 |
Correct |
14 ms |
25436 KB |
Output is correct |
47 |
Correct |
14 ms |
25288 KB |
Output is correct |
48 |
Correct |
15 ms |
25500 KB |
Output is correct |
49 |
Correct |
14 ms |
25436 KB |
Output is correct |
50 |
Correct |
14 ms |
25332 KB |
Output is correct |
51 |
Correct |
14 ms |
25436 KB |
Output is correct |
52 |
Correct |
310 ms |
46272 KB |
Output is correct |
53 |
Correct |
648 ms |
45244 KB |
Output is correct |
54 |
Correct |
354 ms |
62708 KB |
Output is correct |
55 |
Correct |
376 ms |
45980 KB |
Output is correct |
56 |
Correct |
465 ms |
45888 KB |
Output is correct |
57 |
Correct |
471 ms |
45812 KB |
Output is correct |
58 |
Correct |
362 ms |
45556 KB |
Output is correct |
59 |
Correct |
311 ms |
57744 KB |
Output is correct |
60 |
Correct |
333 ms |
60772 KB |
Output is correct |
61 |
Correct |
287 ms |
46672 KB |
Output is correct |
62 |
Correct |
563 ms |
45132 KB |
Output is correct |
63 |
Correct |
16 ms |
25432 KB |
Output is correct |
64 |
Correct |
14 ms |
25436 KB |
Output is correct |
65 |
Correct |
15 ms |
25432 KB |
Output is correct |
66 |
Correct |
14 ms |
25480 KB |
Output is correct |
67 |
Correct |
14 ms |
25688 KB |
Output is correct |
68 |
Correct |
14 ms |
25436 KB |
Output is correct |
69 |
Correct |
15 ms |
25396 KB |
Output is correct |
70 |
Correct |
15 ms |
25460 KB |
Output is correct |
71 |
Correct |
14 ms |
25520 KB |
Output is correct |
72 |
Correct |
14 ms |
25396 KB |
Output is correct |
73 |
Correct |
14 ms |
25432 KB |
Output is correct |
74 |
Correct |
14 ms |
25436 KB |
Output is correct |
75 |
Correct |
14 ms |
25436 KB |
Output is correct |
76 |
Correct |
14 ms |
25436 KB |
Output is correct |
77 |
Correct |
16 ms |
25688 KB |
Output is correct |
78 |
Correct |
13 ms |
25360 KB |
Output is correct |
79 |
Correct |
378 ms |
60916 KB |
Output is correct |
80 |
Correct |
889 ms |
55888 KB |
Output is correct |
81 |
Correct |
492 ms |
57044 KB |
Output is correct |
82 |
Correct |
1774 ms |
43744 KB |
Output is correct |
83 |
Correct |
1195 ms |
43240 KB |
Output is correct |
84 |
Correct |
740 ms |
43836 KB |
Output is correct |
85 |
Correct |
306 ms |
43092 KB |
Output is correct |
86 |
Correct |
356 ms |
54828 KB |
Output is correct |
87 |
Correct |
936 ms |
59352 KB |
Output is correct |
88 |
Correct |
802 ms |
43908 KB |
Output is correct |
89 |
Execution timed out |
4019 ms |
43296 KB |
Time limit exceeded |
90 |
Halted |
0 ms |
0 KB |
- |