#include<bits/stdc++.h>
using namespace std;
const long long maxn=200000+10;
vector<long long>adj[maxn];
long long q,high[maxn],n,mod,timea=0,part[maxn];
pair<long long,long long>stf[maxn];
struct segment{
vector<long long>seg;
long long sz=0;
void create(){
while(__builtin_popcount(sz)!=1){
sz++;
}
seg.resize(sz*2,1);
}
void add(long long i,long long l,long long r,long long tl,long long tr,long long w){
if(l>r||l>tr||r<tl||tl>tr){
return ;
}
if(l>=tl&&r<=tr){
seg[i]*=w;
seg[i]%=mod;
return ;
}
long long m=(l+r)>>1;
add((i<<1),l,m,tl,tr,w);
add((i<<1)^1,m+1,r,tl,tr,w);
return ;
}
long long pors(long long i){
if(i==0){
return 1;
}
long long ret=pors((i>>1))*seg[i]%mod;
return ret;
}
}seg[maxn];
vector<pair<long long,long long>>alll[maxn];
void pre(long long u=1,long long 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(long long u,long long dis,long long w){
long long z=0;
long long lev=high[u]+dis;
while(lev>=0&&high[u]<=lev){
if(lev<maxn){
long long l=lower_bound(alll[lev].begin(),alll[lev].end(),make_pair(stf[u].first,-1ll))-alll[lev].begin();
long long r=lower_bound(alll[lev].begin(),alll[lev].end(),make_pair(stf[u].second+1,-1ll))-alll[lev].begin();
//cout<<u<<" "<<dis<<" "<<w<<" "<<l<<" "<<r<<" "<<lev<<endl;
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(long long u){
long long ind=lower_bound(alll[high[u]].begin(),alll[high[u]].end(),make_pair(stf[u].first,u))-alll[high[u]].begin();
//cout<<u<<" wtf "<<ind<<endl;
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(long long i=0;i<n-1;i++){
long long u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
pre(1);
for(long long i=0;i<maxn;i++){
seg[i].sz=alll[i].size();
seg[i].create();
}
for(long long i=1;i<=n;i++){
long long d;
cin>>d;
upd(i,0,d);
}
cin>>q;
for(long long i=0;i<q;i++){
long long qq;
cin>>qq;
if(qq==1){
long long u,d,w;
cin>>u>>d>>w;
upd(u,d,w);
}
else{
long long u;
cin>>u;
solve(u);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28508 KB |
Output is correct |
2 |
Correct |
14 ms |
28476 KB |
Output is correct |
3 |
Correct |
15 ms |
28508 KB |
Output is correct |
4 |
Correct |
15 ms |
28736 KB |
Output is correct |
5 |
Correct |
15 ms |
28764 KB |
Output is correct |
6 |
Correct |
15 ms |
29016 KB |
Output is correct |
7 |
Correct |
16 ms |
28764 KB |
Output is correct |
8 |
Correct |
15 ms |
28508 KB |
Output is correct |
9 |
Correct |
15 ms |
28504 KB |
Output is correct |
10 |
Correct |
15 ms |
28508 KB |
Output is correct |
11 |
Correct |
16 ms |
28504 KB |
Output is correct |
12 |
Correct |
14 ms |
28580 KB |
Output is correct |
13 |
Correct |
14 ms |
28504 KB |
Output is correct |
14 |
Correct |
14 ms |
28508 KB |
Output is correct |
15 |
Correct |
15 ms |
28560 KB |
Output is correct |
16 |
Correct |
15 ms |
28760 KB |
Output is correct |
17 |
Correct |
14 ms |
28508 KB |
Output is correct |
18 |
Correct |
14 ms |
28480 KB |
Output is correct |
19 |
Correct |
14 ms |
28508 KB |
Output is correct |
20 |
Correct |
14 ms |
28600 KB |
Output is correct |
21 |
Correct |
14 ms |
28504 KB |
Output is correct |
22 |
Correct |
15 ms |
28508 KB |
Output is correct |
23 |
Correct |
17 ms |
28508 KB |
Output is correct |
24 |
Correct |
15 ms |
28508 KB |
Output is correct |
25 |
Correct |
15 ms |
28472 KB |
Output is correct |
26 |
Correct |
15 ms |
28508 KB |
Output is correct |
27 |
Correct |
14 ms |
28508 KB |
Output is correct |
28 |
Correct |
14 ms |
28504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
28504 KB |
Output is correct |
2 |
Correct |
356 ms |
48620 KB |
Output is correct |
3 |
Correct |
503 ms |
57320 KB |
Output is correct |
4 |
Correct |
381 ms |
65288 KB |
Output is correct |
5 |
Correct |
420 ms |
56992 KB |
Output is correct |
6 |
Correct |
469 ms |
55708 KB |
Output is correct |
7 |
Correct |
472 ms |
56052 KB |
Output is correct |
8 |
Correct |
413 ms |
55820 KB |
Output is correct |
9 |
Correct |
379 ms |
71184 KB |
Output is correct |
10 |
Correct |
446 ms |
70312 KB |
Output is correct |
11 |
Correct |
341 ms |
56404 KB |
Output is correct |
12 |
Correct |
510 ms |
57444 KB |
Output is correct |
13 |
Correct |
348 ms |
56760 KB |
Output is correct |
14 |
Correct |
414 ms |
57316 KB |
Output is correct |
15 |
Correct |
412 ms |
56072 KB |
Output is correct |
16 |
Correct |
434 ms |
56480 KB |
Output is correct |
17 |
Correct |
464 ms |
56884 KB |
Output is correct |
18 |
Correct |
15 ms |
28504 KB |
Output is correct |
19 |
Correct |
14 ms |
28504 KB |
Output is correct |
20 |
Correct |
14 ms |
28508 KB |
Output is correct |
21 |
Correct |
15 ms |
28516 KB |
Output is correct |
22 |
Correct |
14 ms |
28552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
28504 KB |
Output is correct |
2 |
Correct |
356 ms |
48620 KB |
Output is correct |
3 |
Correct |
503 ms |
57320 KB |
Output is correct |
4 |
Correct |
381 ms |
65288 KB |
Output is correct |
5 |
Correct |
420 ms |
56992 KB |
Output is correct |
6 |
Correct |
469 ms |
55708 KB |
Output is correct |
7 |
Correct |
472 ms |
56052 KB |
Output is correct |
8 |
Correct |
413 ms |
55820 KB |
Output is correct |
9 |
Correct |
379 ms |
71184 KB |
Output is correct |
10 |
Correct |
446 ms |
70312 KB |
Output is correct |
11 |
Correct |
341 ms |
56404 KB |
Output is correct |
12 |
Correct |
510 ms |
57444 KB |
Output is correct |
13 |
Correct |
348 ms |
56760 KB |
Output is correct |
14 |
Correct |
414 ms |
57316 KB |
Output is correct |
15 |
Correct |
412 ms |
56072 KB |
Output is correct |
16 |
Correct |
434 ms |
56480 KB |
Output is correct |
17 |
Correct |
464 ms |
56884 KB |
Output is correct |
18 |
Correct |
15 ms |
28504 KB |
Output is correct |
19 |
Correct |
14 ms |
28504 KB |
Output is correct |
20 |
Correct |
14 ms |
28508 KB |
Output is correct |
21 |
Correct |
15 ms |
28516 KB |
Output is correct |
22 |
Correct |
14 ms |
28552 KB |
Output is correct |
23 |
Correct |
14 ms |
28560 KB |
Output is correct |
24 |
Correct |
374 ms |
56716 KB |
Output is correct |
25 |
Correct |
668 ms |
57412 KB |
Output is correct |
26 |
Correct |
386 ms |
70484 KB |
Output is correct |
27 |
Correct |
507 ms |
56708 KB |
Output is correct |
28 |
Correct |
586 ms |
56196 KB |
Output is correct |
29 |
Correct |
527 ms |
56224 KB |
Output is correct |
30 |
Correct |
378 ms |
55904 KB |
Output is correct |
31 |
Correct |
344 ms |
65628 KB |
Output is correct |
32 |
Correct |
425 ms |
70084 KB |
Output is correct |
33 |
Correct |
369 ms |
56644 KB |
Output is correct |
34 |
Correct |
736 ms |
57144 KB |
Output is correct |
35 |
Correct |
16 ms |
28508 KB |
Output is correct |
36 |
Correct |
14 ms |
28504 KB |
Output is correct |
37 |
Correct |
14 ms |
28504 KB |
Output is correct |
38 |
Correct |
14 ms |
28508 KB |
Output is correct |
39 |
Correct |
15 ms |
28592 KB |
Output is correct |
40 |
Correct |
14 ms |
28504 KB |
Output is correct |
41 |
Correct |
14 ms |
28632 KB |
Output is correct |
42 |
Correct |
14 ms |
28508 KB |
Output is correct |
43 |
Correct |
14 ms |
28648 KB |
Output is correct |
44 |
Correct |
14 ms |
28508 KB |
Output is correct |
45 |
Correct |
14 ms |
28508 KB |
Output is correct |
46 |
Correct |
14 ms |
28508 KB |
Output is correct |
47 |
Correct |
14 ms |
28508 KB |
Output is correct |
48 |
Correct |
15 ms |
28508 KB |
Output is correct |
49 |
Correct |
14 ms |
28508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28508 KB |
Output is correct |
2 |
Correct |
506 ms |
59936 KB |
Output is correct |
3 |
Correct |
1708 ms |
54784 KB |
Output is correct |
4 |
Correct |
780 ms |
56148 KB |
Output is correct |
5 |
Correct |
2013 ms |
45100 KB |
Output is correct |
6 |
Correct |
1335 ms |
44352 KB |
Output is correct |
7 |
Correct |
846 ms |
45104 KB |
Output is correct |
8 |
Correct |
347 ms |
43928 KB |
Output is correct |
9 |
Correct |
508 ms |
54732 KB |
Output is correct |
10 |
Correct |
1572 ms |
57428 KB |
Output is correct |
11 |
Correct |
959 ms |
46224 KB |
Output is correct |
12 |
Execution timed out |
4054 ms |
45384 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28504 KB |
Output is correct |
2 |
Correct |
490 ms |
56772 KB |
Output is correct |
3 |
Correct |
1739 ms |
60572 KB |
Output is correct |
4 |
Correct |
809 ms |
62544 KB |
Output is correct |
5 |
Correct |
1837 ms |
55552 KB |
Output is correct |
6 |
Correct |
1194 ms |
54816 KB |
Output is correct |
7 |
Correct |
945 ms |
54104 KB |
Output is correct |
8 |
Correct |
376 ms |
54188 KB |
Output is correct |
9 |
Correct |
506 ms |
69456 KB |
Output is correct |
10 |
Correct |
1613 ms |
68292 KB |
Output is correct |
11 |
Correct |
932 ms |
56188 KB |
Output is correct |
12 |
Execution timed out |
4016 ms |
53208 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28508 KB |
Output is correct |
2 |
Correct |
14 ms |
28476 KB |
Output is correct |
3 |
Correct |
15 ms |
28508 KB |
Output is correct |
4 |
Correct |
15 ms |
28736 KB |
Output is correct |
5 |
Correct |
15 ms |
28764 KB |
Output is correct |
6 |
Correct |
15 ms |
29016 KB |
Output is correct |
7 |
Correct |
16 ms |
28764 KB |
Output is correct |
8 |
Correct |
15 ms |
28508 KB |
Output is correct |
9 |
Correct |
15 ms |
28504 KB |
Output is correct |
10 |
Correct |
15 ms |
28508 KB |
Output is correct |
11 |
Correct |
16 ms |
28504 KB |
Output is correct |
12 |
Correct |
14 ms |
28580 KB |
Output is correct |
13 |
Correct |
14 ms |
28504 KB |
Output is correct |
14 |
Correct |
14 ms |
28508 KB |
Output is correct |
15 |
Correct |
15 ms |
28560 KB |
Output is correct |
16 |
Correct |
15 ms |
28760 KB |
Output is correct |
17 |
Correct |
14 ms |
28508 KB |
Output is correct |
18 |
Correct |
14 ms |
28480 KB |
Output is correct |
19 |
Correct |
14 ms |
28508 KB |
Output is correct |
20 |
Correct |
14 ms |
28600 KB |
Output is correct |
21 |
Correct |
14 ms |
28504 KB |
Output is correct |
22 |
Correct |
15 ms |
28508 KB |
Output is correct |
23 |
Correct |
17 ms |
28508 KB |
Output is correct |
24 |
Correct |
15 ms |
28508 KB |
Output is correct |
25 |
Correct |
15 ms |
28472 KB |
Output is correct |
26 |
Correct |
15 ms |
28508 KB |
Output is correct |
27 |
Correct |
14 ms |
28508 KB |
Output is correct |
28 |
Correct |
14 ms |
28504 KB |
Output is correct |
29 |
Correct |
17 ms |
28504 KB |
Output is correct |
30 |
Correct |
356 ms |
48620 KB |
Output is correct |
31 |
Correct |
503 ms |
57320 KB |
Output is correct |
32 |
Correct |
381 ms |
65288 KB |
Output is correct |
33 |
Correct |
420 ms |
56992 KB |
Output is correct |
34 |
Correct |
469 ms |
55708 KB |
Output is correct |
35 |
Correct |
472 ms |
56052 KB |
Output is correct |
36 |
Correct |
413 ms |
55820 KB |
Output is correct |
37 |
Correct |
379 ms |
71184 KB |
Output is correct |
38 |
Correct |
446 ms |
70312 KB |
Output is correct |
39 |
Correct |
341 ms |
56404 KB |
Output is correct |
40 |
Correct |
510 ms |
57444 KB |
Output is correct |
41 |
Correct |
348 ms |
56760 KB |
Output is correct |
42 |
Correct |
414 ms |
57316 KB |
Output is correct |
43 |
Correct |
412 ms |
56072 KB |
Output is correct |
44 |
Correct |
434 ms |
56480 KB |
Output is correct |
45 |
Correct |
464 ms |
56884 KB |
Output is correct |
46 |
Correct |
15 ms |
28504 KB |
Output is correct |
47 |
Correct |
14 ms |
28504 KB |
Output is correct |
48 |
Correct |
14 ms |
28508 KB |
Output is correct |
49 |
Correct |
15 ms |
28516 KB |
Output is correct |
50 |
Correct |
14 ms |
28552 KB |
Output is correct |
51 |
Correct |
14 ms |
28560 KB |
Output is correct |
52 |
Correct |
374 ms |
56716 KB |
Output is correct |
53 |
Correct |
668 ms |
57412 KB |
Output is correct |
54 |
Correct |
386 ms |
70484 KB |
Output is correct |
55 |
Correct |
507 ms |
56708 KB |
Output is correct |
56 |
Correct |
586 ms |
56196 KB |
Output is correct |
57 |
Correct |
527 ms |
56224 KB |
Output is correct |
58 |
Correct |
378 ms |
55904 KB |
Output is correct |
59 |
Correct |
344 ms |
65628 KB |
Output is correct |
60 |
Correct |
425 ms |
70084 KB |
Output is correct |
61 |
Correct |
369 ms |
56644 KB |
Output is correct |
62 |
Correct |
736 ms |
57144 KB |
Output is correct |
63 |
Correct |
16 ms |
28508 KB |
Output is correct |
64 |
Correct |
14 ms |
28504 KB |
Output is correct |
65 |
Correct |
14 ms |
28504 KB |
Output is correct |
66 |
Correct |
14 ms |
28508 KB |
Output is correct |
67 |
Correct |
15 ms |
28592 KB |
Output is correct |
68 |
Correct |
14 ms |
28504 KB |
Output is correct |
69 |
Correct |
14 ms |
28632 KB |
Output is correct |
70 |
Correct |
14 ms |
28508 KB |
Output is correct |
71 |
Correct |
14 ms |
28648 KB |
Output is correct |
72 |
Correct |
14 ms |
28508 KB |
Output is correct |
73 |
Correct |
14 ms |
28508 KB |
Output is correct |
74 |
Correct |
14 ms |
28508 KB |
Output is correct |
75 |
Correct |
14 ms |
28508 KB |
Output is correct |
76 |
Correct |
15 ms |
28508 KB |
Output is correct |
77 |
Correct |
14 ms |
28508 KB |
Output is correct |
78 |
Correct |
14 ms |
28508 KB |
Output is correct |
79 |
Correct |
506 ms |
59936 KB |
Output is correct |
80 |
Correct |
1708 ms |
54784 KB |
Output is correct |
81 |
Correct |
780 ms |
56148 KB |
Output is correct |
82 |
Correct |
2013 ms |
45100 KB |
Output is correct |
83 |
Correct |
1335 ms |
44352 KB |
Output is correct |
84 |
Correct |
846 ms |
45104 KB |
Output is correct |
85 |
Correct |
347 ms |
43928 KB |
Output is correct |
86 |
Correct |
508 ms |
54732 KB |
Output is correct |
87 |
Correct |
1572 ms |
57428 KB |
Output is correct |
88 |
Correct |
959 ms |
46224 KB |
Output is correct |
89 |
Execution timed out |
4054 ms |
45384 KB |
Time limit exceeded |
90 |
Halted |
0 ms |
0 KB |
- |