#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,l;
cin >> n >> l;
vector<vector<int>> adj(n+41);
for(int i=1;i<n;i++){
int a,b;cin>>a>>b;
adj[a].emplace_back(b);
adj[b].emplace_back(a);
}
for(int i=n+1;i<=n+40;i++){
adj[i].emplace_back(i-1);
adj[i-1].emplace_back(i);
}
vector<int> H(n+41);
vector<vector<int>> lazy(n+41,vector<int>(42,1));
vector<int> p(n+41);
for(int i=1;i<=n;i++)cin>>H[i];
function<void(int,int)> dfs = [&](int x,int par){
p[x] = par;
for(int&i:adj[x])if(i!=par)dfs(i,x);
};
dfs(n+40,0);
auto getoffset = [&](int x){
int ans = 1;
for(int i=0;i<=40;i++){
ans=(((ans*lazy[x][i])%l)*lazy[x][i+1])%l;
x = p[x];
if(x==0)break;
}
return ans;
};
auto makeoffset = [&](int x,int w,int d){
for(int i=d;i>=0;i--){
lazy[x][i] = (lazy[x][i]*w)%l;
x = p[x];
if(x==0)break;
}
};
int q;
cin >> q;
for(int i=1;i<=q;i++){
int type;cin>>type;
if(type==1){
int x,d,w;cin>>x>>d>>w;
makeoffset(x,w,d);
} else {
int x;cin>>x;
cout << (H[x]*getoffset(x))%l << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
720 KB |
Output is correct |
6 |
Correct |
1 ms |
944 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
452 KB |
Output is correct |
2 |
Correct |
571 ms |
100956 KB |
Output is correct |
3 |
Correct |
341 ms |
101440 KB |
Output is correct |
4 |
Correct |
501 ms |
110160 KB |
Output is correct |
5 |
Correct |
433 ms |
101204 KB |
Output is correct |
6 |
Correct |
359 ms |
100692 KB |
Output is correct |
7 |
Correct |
349 ms |
101632 KB |
Output is correct |
8 |
Correct |
342 ms |
101692 KB |
Output is correct |
9 |
Correct |
647 ms |
110420 KB |
Output is correct |
10 |
Correct |
355 ms |
112208 KB |
Output is correct |
11 |
Correct |
607 ms |
100976 KB |
Output is correct |
12 |
Correct |
315 ms |
101456 KB |
Output is correct |
13 |
Correct |
225 ms |
101304 KB |
Output is correct |
14 |
Correct |
212 ms |
101820 KB |
Output is correct |
15 |
Correct |
212 ms |
101048 KB |
Output is correct |
16 |
Correct |
230 ms |
101712 KB |
Output is correct |
17 |
Correct |
238 ms |
102224 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
452 KB |
Output is correct |
2 |
Correct |
571 ms |
100956 KB |
Output is correct |
3 |
Correct |
341 ms |
101440 KB |
Output is correct |
4 |
Correct |
501 ms |
110160 KB |
Output is correct |
5 |
Correct |
433 ms |
101204 KB |
Output is correct |
6 |
Correct |
359 ms |
100692 KB |
Output is correct |
7 |
Correct |
349 ms |
101632 KB |
Output is correct |
8 |
Correct |
342 ms |
101692 KB |
Output is correct |
9 |
Correct |
647 ms |
110420 KB |
Output is correct |
10 |
Correct |
355 ms |
112208 KB |
Output is correct |
11 |
Correct |
607 ms |
100976 KB |
Output is correct |
12 |
Correct |
315 ms |
101456 KB |
Output is correct |
13 |
Correct |
225 ms |
101304 KB |
Output is correct |
14 |
Correct |
212 ms |
101820 KB |
Output is correct |
15 |
Correct |
212 ms |
101048 KB |
Output is correct |
16 |
Correct |
230 ms |
101712 KB |
Output is correct |
17 |
Correct |
238 ms |
102224 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
531 ms |
100860 KB |
Output is correct |
25 |
Correct |
318 ms |
101404 KB |
Output is correct |
26 |
Correct |
495 ms |
116820 KB |
Output is correct |
27 |
Correct |
430 ms |
101204 KB |
Output is correct |
28 |
Correct |
364 ms |
101196 KB |
Output is correct |
29 |
Correct |
347 ms |
91220 KB |
Output is correct |
30 |
Correct |
322 ms |
99800 KB |
Output is correct |
31 |
Correct |
654 ms |
114516 KB |
Output is correct |
32 |
Correct |
351 ms |
108452 KB |
Output is correct |
33 |
Correct |
558 ms |
95740 KB |
Output is correct |
34 |
Correct |
309 ms |
89940 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
686 ms |
100216 KB |
Output is correct |
3 |
Correct |
666 ms |
113032 KB |
Output is correct |
4 |
Correct |
612 ms |
115684 KB |
Output is correct |
5 |
Correct |
515 ms |
98148 KB |
Output is correct |
6 |
Correct |
368 ms |
98384 KB |
Output is correct |
7 |
Correct |
365 ms |
98584 KB |
Output is correct |
8 |
Correct |
314 ms |
98752 KB |
Output is correct |
9 |
Correct |
656 ms |
107864 KB |
Output is correct |
10 |
Correct |
710 ms |
115028 KB |
Output is correct |
11 |
Correct |
583 ms |
97824 KB |
Output is correct |
12 |
Correct |
597 ms |
98896 KB |
Output is correct |
13 |
Correct |
435 ms |
99664 KB |
Output is correct |
14 |
Correct |
486 ms |
100516 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
689 ms |
106884 KB |
Output is correct |
3 |
Correct |
677 ms |
106320 KB |
Output is correct |
4 |
Correct |
652 ms |
114576 KB |
Output is correct |
5 |
Correct |
506 ms |
99920 KB |
Output is correct |
6 |
Correct |
382 ms |
99924 KB |
Output is correct |
7 |
Correct |
378 ms |
99616 KB |
Output is correct |
8 |
Correct |
329 ms |
99780 KB |
Output is correct |
9 |
Correct |
726 ms |
114872 KB |
Output is correct |
10 |
Correct |
694 ms |
109808 KB |
Output is correct |
11 |
Correct |
573 ms |
100704 KB |
Output is correct |
12 |
Correct |
592 ms |
98992 KB |
Output is correct |
13 |
Correct |
372 ms |
99924 KB |
Output is correct |
14 |
Correct |
425 ms |
100692 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
720 KB |
Output is correct |
6 |
Correct |
1 ms |
944 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
452 KB |
Output is correct |
30 |
Correct |
571 ms |
100956 KB |
Output is correct |
31 |
Correct |
341 ms |
101440 KB |
Output is correct |
32 |
Correct |
501 ms |
110160 KB |
Output is correct |
33 |
Correct |
433 ms |
101204 KB |
Output is correct |
34 |
Correct |
359 ms |
100692 KB |
Output is correct |
35 |
Correct |
349 ms |
101632 KB |
Output is correct |
36 |
Correct |
342 ms |
101692 KB |
Output is correct |
37 |
Correct |
647 ms |
110420 KB |
Output is correct |
38 |
Correct |
355 ms |
112208 KB |
Output is correct |
39 |
Correct |
607 ms |
100976 KB |
Output is correct |
40 |
Correct |
315 ms |
101456 KB |
Output is correct |
41 |
Correct |
225 ms |
101304 KB |
Output is correct |
42 |
Correct |
212 ms |
101820 KB |
Output is correct |
43 |
Correct |
212 ms |
101048 KB |
Output is correct |
44 |
Correct |
230 ms |
101712 KB |
Output is correct |
45 |
Correct |
238 ms |
102224 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
531 ms |
100860 KB |
Output is correct |
53 |
Correct |
318 ms |
101404 KB |
Output is correct |
54 |
Correct |
495 ms |
116820 KB |
Output is correct |
55 |
Correct |
430 ms |
101204 KB |
Output is correct |
56 |
Correct |
364 ms |
101196 KB |
Output is correct |
57 |
Correct |
347 ms |
91220 KB |
Output is correct |
58 |
Correct |
322 ms |
99800 KB |
Output is correct |
59 |
Correct |
654 ms |
114516 KB |
Output is correct |
60 |
Correct |
351 ms |
108452 KB |
Output is correct |
61 |
Correct |
558 ms |
95740 KB |
Output is correct |
62 |
Correct |
309 ms |
89940 KB |
Output is correct |
63 |
Correct |
1 ms |
344 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
1 ms |
348 KB |
Output is correct |
66 |
Correct |
1 ms |
348 KB |
Output is correct |
67 |
Correct |
1 ms |
348 KB |
Output is correct |
68 |
Correct |
1 ms |
348 KB |
Output is correct |
69 |
Correct |
1 ms |
348 KB |
Output is correct |
70 |
Correct |
1 ms |
348 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
0 ms |
348 KB |
Output is correct |
74 |
Correct |
1 ms |
348 KB |
Output is correct |
75 |
Correct |
1 ms |
348 KB |
Output is correct |
76 |
Correct |
1 ms |
348 KB |
Output is correct |
77 |
Correct |
1 ms |
344 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
686 ms |
100216 KB |
Output is correct |
80 |
Correct |
666 ms |
113032 KB |
Output is correct |
81 |
Correct |
612 ms |
115684 KB |
Output is correct |
82 |
Correct |
515 ms |
98148 KB |
Output is correct |
83 |
Correct |
368 ms |
98384 KB |
Output is correct |
84 |
Correct |
365 ms |
98584 KB |
Output is correct |
85 |
Correct |
314 ms |
98752 KB |
Output is correct |
86 |
Correct |
656 ms |
107864 KB |
Output is correct |
87 |
Correct |
710 ms |
115028 KB |
Output is correct |
88 |
Correct |
583 ms |
97824 KB |
Output is correct |
89 |
Correct |
597 ms |
98896 KB |
Output is correct |
90 |
Correct |
435 ms |
99664 KB |
Output is correct |
91 |
Correct |
486 ms |
100516 KB |
Output is correct |
92 |
Correct |
1 ms |
348 KB |
Output is correct |
93 |
Correct |
1 ms |
348 KB |
Output is correct |
94 |
Correct |
1 ms |
348 KB |
Output is correct |
95 |
Correct |
1 ms |
348 KB |
Output is correct |
96 |
Correct |
1 ms |
348 KB |
Output is correct |
97 |
Correct |
0 ms |
348 KB |
Output is correct |
98 |
Correct |
689 ms |
106884 KB |
Output is correct |
99 |
Correct |
677 ms |
106320 KB |
Output is correct |
100 |
Correct |
652 ms |
114576 KB |
Output is correct |
101 |
Correct |
506 ms |
99920 KB |
Output is correct |
102 |
Correct |
382 ms |
99924 KB |
Output is correct |
103 |
Correct |
378 ms |
99616 KB |
Output is correct |
104 |
Correct |
329 ms |
99780 KB |
Output is correct |
105 |
Correct |
726 ms |
114872 KB |
Output is correct |
106 |
Correct |
694 ms |
109808 KB |
Output is correct |
107 |
Correct |
573 ms |
100704 KB |
Output is correct |
108 |
Correct |
592 ms |
98992 KB |
Output is correct |
109 |
Correct |
372 ms |
99924 KB |
Output is correct |
110 |
Correct |
425 ms |
100692 KB |
Output is correct |
111 |
Correct |
1 ms |
344 KB |
Output is correct |
112 |
Correct |
1 ms |
348 KB |
Output is correct |
113 |
Correct |
1 ms |
348 KB |
Output is correct |
114 |
Correct |
1 ms |
344 KB |
Output is correct |
115 |
Correct |
1 ms |
348 KB |
Output is correct |
116 |
Correct |
592 ms |
99072 KB |
Output is correct |
117 |
Correct |
615 ms |
101740 KB |
Output is correct |
118 |
Correct |
589 ms |
116840 KB |
Output is correct |
119 |
Correct |
520 ms |
101200 KB |
Output is correct |
120 |
Correct |
383 ms |
100948 KB |
Output is correct |
121 |
Correct |
368 ms |
101712 KB |
Output is correct |
122 |
Correct |
326 ms |
101828 KB |
Output is correct |
123 |
Correct |
703 ms |
110700 KB |
Output is correct |
124 |
Correct |
648 ms |
110928 KB |
Output is correct |
125 |
Correct |
531 ms |
100260 KB |
Output is correct |
126 |
Correct |
624 ms |
101544 KB |
Output is correct |
127 |
Correct |
618 ms |
101896 KB |
Output is correct |
128 |
Correct |
394 ms |
102480 KB |
Output is correct |
129 |
Correct |
441 ms |
103504 KB |
Output is correct |