#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 200045;
const int K = 45;
int n, l, q, h[N], val[N][K], pa[N], dep[N];
vector<int> adj[N];
void dfs(int u, int p) {
for (int v : adj[u]) if (v != p) {
dep[v] = dep[u] + 1;
pa[v] = u, dfs(v, u);
}
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> l;
for (int i = 0; i < N; i++) for (int j = 0; j < K; j++) val[i][j] = 1;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
pa[1] = 0;
for (int i = n + 1; i <= n + 39; i++) {
adj[i].push_back(i + 1);
adj[i + 1].push_back(i);
}
adj[n + 40].push_back(1);
adj[1].push_back(n + 40);
dfs(n + 1, -1);
for (int i = 1; i <= n; i++) cin >> h[i];
cin >> q;
while (q--) {
int ty;
cin >> ty;
if (ty == 1) {
int u, d, w;
cin >> u >> d >> w;
d = min(d, dep[u]);
vector<int> tr;
for (int j = 0; j <= d; j++) tr.push_back(u), u = pa[u];
reverse(tr.begin(), tr.end());
int dp = 0;
val[tr[0]][0] = (val[tr[0]][0] * w) % l;
// cout << "upd " << tr[0] << " " << 0 << " " << w << "\n";
for (auto x : tr) {
if (x == tr[0]) continue;
// cout << "x: " << x << '\n';
val[x][dp] = (val[x][dp] * w) % l;
val[x][dp + 1] = (val[x][dp + 1] * w) % l;
// cout << "upd " << x << " " << dp << "\n";
// cout << "upd " << x << " " << dp + 1 << '\n';
++dp;
}
} else {
int u;
cin >> u;
int ans = h[u];
for (int i = 0; i <= 40; i++) {
ans *= val[u][i];
ans %= l;
u = pa[u];
if (!u) break;
}
cout << ans << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
78684 KB |
Output is correct |
2 |
Correct |
11 ms |
78732 KB |
Output is correct |
3 |
Correct |
11 ms |
78732 KB |
Output is correct |
4 |
Correct |
12 ms |
78684 KB |
Output is correct |
5 |
Correct |
12 ms |
78684 KB |
Output is correct |
6 |
Correct |
12 ms |
78684 KB |
Output is correct |
7 |
Correct |
12 ms |
78820 KB |
Output is correct |
8 |
Correct |
12 ms |
78684 KB |
Output is correct |
9 |
Correct |
11 ms |
78684 KB |
Output is correct |
10 |
Correct |
11 ms |
78684 KB |
Output is correct |
11 |
Correct |
11 ms |
78772 KB |
Output is correct |
12 |
Correct |
11 ms |
78684 KB |
Output is correct |
13 |
Correct |
13 ms |
78684 KB |
Output is correct |
14 |
Correct |
14 ms |
78780 KB |
Output is correct |
15 |
Correct |
12 ms |
78684 KB |
Output is correct |
16 |
Correct |
12 ms |
78776 KB |
Output is correct |
17 |
Correct |
11 ms |
78680 KB |
Output is correct |
18 |
Correct |
13 ms |
78680 KB |
Output is correct |
19 |
Correct |
11 ms |
78680 KB |
Output is correct |
20 |
Correct |
11 ms |
78684 KB |
Output is correct |
21 |
Correct |
11 ms |
78744 KB |
Output is correct |
22 |
Correct |
11 ms |
78608 KB |
Output is correct |
23 |
Correct |
11 ms |
78544 KB |
Output is correct |
24 |
Correct |
12 ms |
78684 KB |
Output is correct |
25 |
Correct |
11 ms |
78684 KB |
Output is correct |
26 |
Correct |
11 ms |
78684 KB |
Output is correct |
27 |
Correct |
11 ms |
78684 KB |
Output is correct |
28 |
Correct |
11 ms |
78576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
78680 KB |
Output is correct |
2 |
Correct |
378 ms |
99412 KB |
Output is correct |
3 |
Correct |
238 ms |
99844 KB |
Output is correct |
4 |
Correct |
338 ms |
106476 KB |
Output is correct |
5 |
Correct |
270 ms |
99668 KB |
Output is correct |
6 |
Correct |
230 ms |
99188 KB |
Output is correct |
7 |
Correct |
214 ms |
99924 KB |
Output is correct |
8 |
Correct |
203 ms |
100032 KB |
Output is correct |
9 |
Correct |
435 ms |
110140 KB |
Output is correct |
10 |
Correct |
263 ms |
109648 KB |
Output is correct |
11 |
Correct |
360 ms |
99232 KB |
Output is correct |
12 |
Correct |
227 ms |
99668 KB |
Output is correct |
13 |
Correct |
169 ms |
100032 KB |
Output is correct |
14 |
Correct |
169 ms |
100264 KB |
Output is correct |
15 |
Correct |
167 ms |
99448 KB |
Output is correct |
16 |
Correct |
191 ms |
100180 KB |
Output is correct |
17 |
Correct |
171 ms |
100656 KB |
Output is correct |
18 |
Correct |
14 ms |
78740 KB |
Output is correct |
19 |
Correct |
11 ms |
78684 KB |
Output is correct |
20 |
Correct |
11 ms |
78684 KB |
Output is correct |
21 |
Correct |
11 ms |
78680 KB |
Output is correct |
22 |
Correct |
11 ms |
78684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
78680 KB |
Output is correct |
2 |
Correct |
378 ms |
99412 KB |
Output is correct |
3 |
Correct |
238 ms |
99844 KB |
Output is correct |
4 |
Correct |
338 ms |
106476 KB |
Output is correct |
5 |
Correct |
270 ms |
99668 KB |
Output is correct |
6 |
Correct |
230 ms |
99188 KB |
Output is correct |
7 |
Correct |
214 ms |
99924 KB |
Output is correct |
8 |
Correct |
203 ms |
100032 KB |
Output is correct |
9 |
Correct |
435 ms |
110140 KB |
Output is correct |
10 |
Correct |
263 ms |
109648 KB |
Output is correct |
11 |
Correct |
360 ms |
99232 KB |
Output is correct |
12 |
Correct |
227 ms |
99668 KB |
Output is correct |
13 |
Correct |
169 ms |
100032 KB |
Output is correct |
14 |
Correct |
169 ms |
100264 KB |
Output is correct |
15 |
Correct |
167 ms |
99448 KB |
Output is correct |
16 |
Correct |
191 ms |
100180 KB |
Output is correct |
17 |
Correct |
171 ms |
100656 KB |
Output is correct |
18 |
Correct |
14 ms |
78740 KB |
Output is correct |
19 |
Correct |
11 ms |
78684 KB |
Output is correct |
20 |
Correct |
11 ms |
78684 KB |
Output is correct |
21 |
Correct |
11 ms |
78680 KB |
Output is correct |
22 |
Correct |
11 ms |
78684 KB |
Output is correct |
23 |
Correct |
11 ms |
78684 KB |
Output is correct |
24 |
Correct |
353 ms |
99412 KB |
Output is correct |
25 |
Correct |
261 ms |
99876 KB |
Output is correct |
26 |
Correct |
365 ms |
110016 KB |
Output is correct |
27 |
Correct |
288 ms |
99592 KB |
Output is correct |
28 |
Correct |
246 ms |
99668 KB |
Output is correct |
29 |
Correct |
222 ms |
99416 KB |
Output is correct |
30 |
Correct |
206 ms |
100104 KB |
Output is correct |
31 |
Correct |
407 ms |
106560 KB |
Output is correct |
32 |
Correct |
254 ms |
109920 KB |
Output is correct |
33 |
Correct |
337 ms |
99300 KB |
Output is correct |
34 |
Correct |
223 ms |
99924 KB |
Output is correct |
35 |
Correct |
10 ms |
78684 KB |
Output is correct |
36 |
Correct |
11 ms |
78600 KB |
Output is correct |
37 |
Correct |
11 ms |
78680 KB |
Output is correct |
38 |
Correct |
10 ms |
78680 KB |
Output is correct |
39 |
Correct |
11 ms |
78548 KB |
Output is correct |
40 |
Correct |
10 ms |
78684 KB |
Output is correct |
41 |
Correct |
11 ms |
78588 KB |
Output is correct |
42 |
Correct |
10 ms |
78684 KB |
Output is correct |
43 |
Correct |
14 ms |
78532 KB |
Output is correct |
44 |
Correct |
11 ms |
78540 KB |
Output is correct |
45 |
Correct |
11 ms |
78684 KB |
Output is correct |
46 |
Correct |
11 ms |
78684 KB |
Output is correct |
47 |
Correct |
11 ms |
78776 KB |
Output is correct |
48 |
Correct |
12 ms |
78684 KB |
Output is correct |
49 |
Correct |
11 ms |
78684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
78684 KB |
Output is correct |
2 |
Correct |
443 ms |
107280 KB |
Output is correct |
3 |
Correct |
611 ms |
105128 KB |
Output is correct |
4 |
Correct |
421 ms |
105044 KB |
Output is correct |
5 |
Correct |
341 ms |
96616 KB |
Output is correct |
6 |
Correct |
246 ms |
96852 KB |
Output is correct |
7 |
Correct |
243 ms |
96852 KB |
Output is correct |
8 |
Correct |
241 ms |
97216 KB |
Output is correct |
9 |
Correct |
466 ms |
103764 KB |
Output is correct |
10 |
Correct |
592 ms |
106832 KB |
Output is correct |
11 |
Correct |
348 ms |
96252 KB |
Output is correct |
12 |
Correct |
472 ms |
97172 KB |
Output is correct |
13 |
Correct |
311 ms |
98128 KB |
Output is correct |
14 |
Correct |
338 ms |
98900 KB |
Output is correct |
15 |
Correct |
11 ms |
78680 KB |
Output is correct |
16 |
Correct |
10 ms |
78684 KB |
Output is correct |
17 |
Correct |
10 ms |
78604 KB |
Output is correct |
18 |
Correct |
11 ms |
78684 KB |
Output is correct |
19 |
Correct |
13 ms |
78536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
78600 KB |
Output is correct |
2 |
Correct |
438 ms |
106012 KB |
Output is correct |
3 |
Correct |
583 ms |
102724 KB |
Output is correct |
4 |
Correct |
443 ms |
104212 KB |
Output is correct |
5 |
Correct |
358 ms |
98128 KB |
Output is correct |
6 |
Correct |
284 ms |
98388 KB |
Output is correct |
7 |
Correct |
274 ms |
98144 KB |
Output is correct |
8 |
Correct |
235 ms |
98236 KB |
Output is correct |
9 |
Correct |
438 ms |
109140 KB |
Output is correct |
10 |
Correct |
593 ms |
107856 KB |
Output is correct |
11 |
Correct |
366 ms |
98968 KB |
Output is correct |
12 |
Correct |
457 ms |
97544 KB |
Output is correct |
13 |
Correct |
344 ms |
98132 KB |
Output is correct |
14 |
Correct |
364 ms |
98948 KB |
Output is correct |
15 |
Correct |
11 ms |
78684 KB |
Output is correct |
16 |
Correct |
11 ms |
78700 KB |
Output is correct |
17 |
Correct |
11 ms |
78780 KB |
Output is correct |
18 |
Correct |
12 ms |
78608 KB |
Output is correct |
19 |
Correct |
12 ms |
78684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
78684 KB |
Output is correct |
2 |
Correct |
11 ms |
78732 KB |
Output is correct |
3 |
Correct |
11 ms |
78732 KB |
Output is correct |
4 |
Correct |
12 ms |
78684 KB |
Output is correct |
5 |
Correct |
12 ms |
78684 KB |
Output is correct |
6 |
Correct |
12 ms |
78684 KB |
Output is correct |
7 |
Correct |
12 ms |
78820 KB |
Output is correct |
8 |
Correct |
12 ms |
78684 KB |
Output is correct |
9 |
Correct |
11 ms |
78684 KB |
Output is correct |
10 |
Correct |
11 ms |
78684 KB |
Output is correct |
11 |
Correct |
11 ms |
78772 KB |
Output is correct |
12 |
Correct |
11 ms |
78684 KB |
Output is correct |
13 |
Correct |
13 ms |
78684 KB |
Output is correct |
14 |
Correct |
14 ms |
78780 KB |
Output is correct |
15 |
Correct |
12 ms |
78684 KB |
Output is correct |
16 |
Correct |
12 ms |
78776 KB |
Output is correct |
17 |
Correct |
11 ms |
78680 KB |
Output is correct |
18 |
Correct |
13 ms |
78680 KB |
Output is correct |
19 |
Correct |
11 ms |
78680 KB |
Output is correct |
20 |
Correct |
11 ms |
78684 KB |
Output is correct |
21 |
Correct |
11 ms |
78744 KB |
Output is correct |
22 |
Correct |
11 ms |
78608 KB |
Output is correct |
23 |
Correct |
11 ms |
78544 KB |
Output is correct |
24 |
Correct |
12 ms |
78684 KB |
Output is correct |
25 |
Correct |
11 ms |
78684 KB |
Output is correct |
26 |
Correct |
11 ms |
78684 KB |
Output is correct |
27 |
Correct |
11 ms |
78684 KB |
Output is correct |
28 |
Correct |
11 ms |
78576 KB |
Output is correct |
29 |
Correct |
15 ms |
78680 KB |
Output is correct |
30 |
Correct |
378 ms |
99412 KB |
Output is correct |
31 |
Correct |
238 ms |
99844 KB |
Output is correct |
32 |
Correct |
338 ms |
106476 KB |
Output is correct |
33 |
Correct |
270 ms |
99668 KB |
Output is correct |
34 |
Correct |
230 ms |
99188 KB |
Output is correct |
35 |
Correct |
214 ms |
99924 KB |
Output is correct |
36 |
Correct |
203 ms |
100032 KB |
Output is correct |
37 |
Correct |
435 ms |
110140 KB |
Output is correct |
38 |
Correct |
263 ms |
109648 KB |
Output is correct |
39 |
Correct |
360 ms |
99232 KB |
Output is correct |
40 |
Correct |
227 ms |
99668 KB |
Output is correct |
41 |
Correct |
169 ms |
100032 KB |
Output is correct |
42 |
Correct |
169 ms |
100264 KB |
Output is correct |
43 |
Correct |
167 ms |
99448 KB |
Output is correct |
44 |
Correct |
191 ms |
100180 KB |
Output is correct |
45 |
Correct |
171 ms |
100656 KB |
Output is correct |
46 |
Correct |
14 ms |
78740 KB |
Output is correct |
47 |
Correct |
11 ms |
78684 KB |
Output is correct |
48 |
Correct |
11 ms |
78684 KB |
Output is correct |
49 |
Correct |
11 ms |
78680 KB |
Output is correct |
50 |
Correct |
11 ms |
78684 KB |
Output is correct |
51 |
Correct |
11 ms |
78684 KB |
Output is correct |
52 |
Correct |
353 ms |
99412 KB |
Output is correct |
53 |
Correct |
261 ms |
99876 KB |
Output is correct |
54 |
Correct |
365 ms |
110016 KB |
Output is correct |
55 |
Correct |
288 ms |
99592 KB |
Output is correct |
56 |
Correct |
246 ms |
99668 KB |
Output is correct |
57 |
Correct |
222 ms |
99416 KB |
Output is correct |
58 |
Correct |
206 ms |
100104 KB |
Output is correct |
59 |
Correct |
407 ms |
106560 KB |
Output is correct |
60 |
Correct |
254 ms |
109920 KB |
Output is correct |
61 |
Correct |
337 ms |
99300 KB |
Output is correct |
62 |
Correct |
223 ms |
99924 KB |
Output is correct |
63 |
Correct |
10 ms |
78684 KB |
Output is correct |
64 |
Correct |
11 ms |
78600 KB |
Output is correct |
65 |
Correct |
11 ms |
78680 KB |
Output is correct |
66 |
Correct |
10 ms |
78680 KB |
Output is correct |
67 |
Correct |
11 ms |
78548 KB |
Output is correct |
68 |
Correct |
10 ms |
78684 KB |
Output is correct |
69 |
Correct |
11 ms |
78588 KB |
Output is correct |
70 |
Correct |
10 ms |
78684 KB |
Output is correct |
71 |
Correct |
14 ms |
78532 KB |
Output is correct |
72 |
Correct |
11 ms |
78540 KB |
Output is correct |
73 |
Correct |
11 ms |
78684 KB |
Output is correct |
74 |
Correct |
11 ms |
78684 KB |
Output is correct |
75 |
Correct |
11 ms |
78776 KB |
Output is correct |
76 |
Correct |
12 ms |
78684 KB |
Output is correct |
77 |
Correct |
11 ms |
78684 KB |
Output is correct |
78 |
Correct |
11 ms |
78684 KB |
Output is correct |
79 |
Correct |
443 ms |
107280 KB |
Output is correct |
80 |
Correct |
611 ms |
105128 KB |
Output is correct |
81 |
Correct |
421 ms |
105044 KB |
Output is correct |
82 |
Correct |
341 ms |
96616 KB |
Output is correct |
83 |
Correct |
246 ms |
96852 KB |
Output is correct |
84 |
Correct |
243 ms |
96852 KB |
Output is correct |
85 |
Correct |
241 ms |
97216 KB |
Output is correct |
86 |
Correct |
466 ms |
103764 KB |
Output is correct |
87 |
Correct |
592 ms |
106832 KB |
Output is correct |
88 |
Correct |
348 ms |
96252 KB |
Output is correct |
89 |
Correct |
472 ms |
97172 KB |
Output is correct |
90 |
Correct |
311 ms |
98128 KB |
Output is correct |
91 |
Correct |
338 ms |
98900 KB |
Output is correct |
92 |
Correct |
11 ms |
78680 KB |
Output is correct |
93 |
Correct |
10 ms |
78684 KB |
Output is correct |
94 |
Correct |
10 ms |
78604 KB |
Output is correct |
95 |
Correct |
11 ms |
78684 KB |
Output is correct |
96 |
Correct |
13 ms |
78536 KB |
Output is correct |
97 |
Correct |
10 ms |
78600 KB |
Output is correct |
98 |
Correct |
438 ms |
106012 KB |
Output is correct |
99 |
Correct |
583 ms |
102724 KB |
Output is correct |
100 |
Correct |
443 ms |
104212 KB |
Output is correct |
101 |
Correct |
358 ms |
98128 KB |
Output is correct |
102 |
Correct |
284 ms |
98388 KB |
Output is correct |
103 |
Correct |
274 ms |
98144 KB |
Output is correct |
104 |
Correct |
235 ms |
98236 KB |
Output is correct |
105 |
Correct |
438 ms |
109140 KB |
Output is correct |
106 |
Correct |
593 ms |
107856 KB |
Output is correct |
107 |
Correct |
366 ms |
98968 KB |
Output is correct |
108 |
Correct |
457 ms |
97544 KB |
Output is correct |
109 |
Correct |
344 ms |
98132 KB |
Output is correct |
110 |
Correct |
364 ms |
98948 KB |
Output is correct |
111 |
Correct |
11 ms |
78684 KB |
Output is correct |
112 |
Correct |
11 ms |
78700 KB |
Output is correct |
113 |
Correct |
11 ms |
78780 KB |
Output is correct |
114 |
Correct |
12 ms |
78608 KB |
Output is correct |
115 |
Correct |
12 ms |
78684 KB |
Output is correct |
116 |
Correct |
357 ms |
97364 KB |
Output is correct |
117 |
Correct |
479 ms |
99924 KB |
Output is correct |
118 |
Correct |
462 ms |
109908 KB |
Output is correct |
119 |
Correct |
369 ms |
99664 KB |
Output is correct |
120 |
Correct |
298 ms |
99280 KB |
Output is correct |
121 |
Correct |
263 ms |
100076 KB |
Output is correct |
122 |
Correct |
244 ms |
100032 KB |
Output is correct |
123 |
Correct |
451 ms |
107908 KB |
Output is correct |
124 |
Correct |
714 ms |
105812 KB |
Output is correct |
125 |
Correct |
365 ms |
98384 KB |
Output is correct |
126 |
Correct |
494 ms |
99924 KB |
Output is correct |
127 |
Correct |
499 ms |
100216 KB |
Output is correct |
128 |
Correct |
387 ms |
100948 KB |
Output is correct |
129 |
Correct |
371 ms |
101916 KB |
Output is correct |