#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>
using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;
void Hollwo_Pelw();
signed main(){
#ifndef hollwo_pelw_local
if (fopen(".inp", "r"))
assert(freopen(".inp", "r", stdin)), assert(freopen(".out", "w", stdout));
#else
using namespace chrono;
auto start = steady_clock::now();
#endif
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
int testcases = 1;
// cin >> testcases;
for (int test = 1; test <= testcases; test++){
// cout << "Case #" << test << ": ";
Hollwo_Pelw();
}
#ifdef hollwo_pelw_local
auto end = steady_clock::now();
cout << "\nExecution time : " << duration_cast<milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}
const int N = 2e5 + 5;
int n, q, mod, par[N];
long long h[N], keep[N][45];
vector<int> adj[N];
void pre_dfs(int u, int p) {
par[u] = p;
for (int v : adj[u]) if (v != p) {
pre_dfs(v, u);
}
}
void Hollwo_Pelw(){
cin >> n >> mod;
for (int i = 1, u, v; i < n; i++) {
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
pre_dfs(1, 0);
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= 40; j++)
keep[i][j] = 1;
}
cin >> q;
for (int t; q --; ) {
cin >> t;
if (t == 1) {
// update
int x, d, w; cin >> x >> d >> w;
for (int p = x; p && d >= 0; p = par[p], d --) {
(keep[p][d] *= w) %= mod;
if (d) (keep[p][d - 1] *= w) %= mod;
}
for (d --; d >= 0; d --)
(keep[1][d] *= w) %= mod;
} else {
// query
int x; cin >> x;
long long res = h[x];
for (int p = x, d = 0; p && d <= 40; p = par[p], d ++)
(res *= keep[p][d]) %= mod;
cout << res << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5036 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
5 ms |
5332 KB |
Output is correct |
5 |
Correct |
4 ms |
5424 KB |
Output is correct |
6 |
Correct |
4 ms |
5356 KB |
Output is correct |
7 |
Correct |
4 ms |
5460 KB |
Output is correct |
8 |
Correct |
5 ms |
5480 KB |
Output is correct |
9 |
Correct |
3 ms |
5040 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
5040 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5036 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
3 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
5040 KB |
Output is correct |
26 |
Correct |
4 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
5036 KB |
Output is correct |
28 |
Correct |
3 ms |
5040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
538 ms |
87700 KB |
Output is correct |
3 |
Correct |
323 ms |
84456 KB |
Output is correct |
4 |
Correct |
454 ms |
88848 KB |
Output is correct |
5 |
Correct |
464 ms |
86180 KB |
Output is correct |
6 |
Correct |
363 ms |
85948 KB |
Output is correct |
7 |
Correct |
349 ms |
86452 KB |
Output is correct |
8 |
Correct |
239 ms |
86820 KB |
Output is correct |
9 |
Correct |
608 ms |
91844 KB |
Output is correct |
10 |
Correct |
408 ms |
88392 KB |
Output is correct |
11 |
Correct |
571 ms |
87656 KB |
Output is correct |
12 |
Correct |
364 ms |
96296 KB |
Output is correct |
13 |
Correct |
263 ms |
96724 KB |
Output is correct |
14 |
Correct |
246 ms |
97160 KB |
Output is correct |
15 |
Correct |
238 ms |
96512 KB |
Output is correct |
16 |
Correct |
256 ms |
96960 KB |
Output is correct |
17 |
Correct |
325 ms |
97540 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
5040 KB |
Output is correct |
22 |
Correct |
4 ms |
5036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
538 ms |
87700 KB |
Output is correct |
3 |
Correct |
323 ms |
84456 KB |
Output is correct |
4 |
Correct |
454 ms |
88848 KB |
Output is correct |
5 |
Correct |
464 ms |
86180 KB |
Output is correct |
6 |
Correct |
363 ms |
85948 KB |
Output is correct |
7 |
Correct |
349 ms |
86452 KB |
Output is correct |
8 |
Correct |
239 ms |
86820 KB |
Output is correct |
9 |
Correct |
608 ms |
91844 KB |
Output is correct |
10 |
Correct |
408 ms |
88392 KB |
Output is correct |
11 |
Correct |
571 ms |
87656 KB |
Output is correct |
12 |
Correct |
364 ms |
96296 KB |
Output is correct |
13 |
Correct |
263 ms |
96724 KB |
Output is correct |
14 |
Correct |
246 ms |
97160 KB |
Output is correct |
15 |
Correct |
238 ms |
96512 KB |
Output is correct |
16 |
Correct |
256 ms |
96960 KB |
Output is correct |
17 |
Correct |
325 ms |
97540 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
5040 KB |
Output is correct |
22 |
Correct |
4 ms |
5036 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
572 ms |
95816 KB |
Output is correct |
25 |
Correct |
359 ms |
96440 KB |
Output is correct |
26 |
Correct |
534 ms |
100232 KB |
Output is correct |
27 |
Correct |
464 ms |
96156 KB |
Output is correct |
28 |
Correct |
319 ms |
96168 KB |
Output is correct |
29 |
Correct |
366 ms |
95920 KB |
Output is correct |
30 |
Correct |
277 ms |
96960 KB |
Output is correct |
31 |
Correct |
605 ms |
98972 KB |
Output is correct |
32 |
Correct |
394 ms |
100296 KB |
Output is correct |
33 |
Correct |
620 ms |
95796 KB |
Output is correct |
34 |
Correct |
351 ms |
96508 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
3 ms |
4948 KB |
Output is correct |
40 |
Correct |
4 ms |
4948 KB |
Output is correct |
41 |
Correct |
4 ms |
5032 KB |
Output is correct |
42 |
Correct |
4 ms |
5032 KB |
Output is correct |
43 |
Correct |
3 ms |
4948 KB |
Output is correct |
44 |
Correct |
3 ms |
4948 KB |
Output is correct |
45 |
Correct |
3 ms |
4948 KB |
Output is correct |
46 |
Correct |
3 ms |
4948 KB |
Output is correct |
47 |
Correct |
3 ms |
5036 KB |
Output is correct |
48 |
Correct |
3 ms |
5036 KB |
Output is correct |
49 |
Correct |
4 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
701 ms |
89244 KB |
Output is correct |
3 |
Correct |
682 ms |
87404 KB |
Output is correct |
4 |
Correct |
524 ms |
87876 KB |
Output is correct |
5 |
Correct |
536 ms |
84640 KB |
Output is correct |
6 |
Correct |
362 ms |
84604 KB |
Output is correct |
7 |
Correct |
329 ms |
84768 KB |
Output is correct |
8 |
Correct |
251 ms |
85232 KB |
Output is correct |
9 |
Correct |
569 ms |
88132 KB |
Output is correct |
10 |
Correct |
774 ms |
88112 KB |
Output is correct |
11 |
Correct |
597 ms |
84916 KB |
Output is correct |
12 |
Correct |
616 ms |
84428 KB |
Output is correct |
13 |
Correct |
381 ms |
85112 KB |
Output is correct |
14 |
Correct |
408 ms |
85520 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
620 ms |
90424 KB |
Output is correct |
3 |
Correct |
814 ms |
96272 KB |
Output is correct |
4 |
Correct |
553 ms |
97208 KB |
Output is correct |
5 |
Correct |
556 ms |
94852 KB |
Output is correct |
6 |
Correct |
403 ms |
95004 KB |
Output is correct |
7 |
Correct |
383 ms |
94856 KB |
Output is correct |
8 |
Correct |
262 ms |
94956 KB |
Output is correct |
9 |
Correct |
600 ms |
99560 KB |
Output is correct |
10 |
Correct |
728 ms |
98028 KB |
Output is correct |
11 |
Correct |
556 ms |
95664 KB |
Output is correct |
12 |
Correct |
632 ms |
93956 KB |
Output is correct |
13 |
Correct |
468 ms |
94680 KB |
Output is correct |
14 |
Correct |
408 ms |
95320 KB |
Output is correct |
15 |
Correct |
3 ms |
5036 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5036 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
5 ms |
5332 KB |
Output is correct |
5 |
Correct |
4 ms |
5424 KB |
Output is correct |
6 |
Correct |
4 ms |
5356 KB |
Output is correct |
7 |
Correct |
4 ms |
5460 KB |
Output is correct |
8 |
Correct |
5 ms |
5480 KB |
Output is correct |
9 |
Correct |
3 ms |
5040 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
5040 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5036 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
3 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
5040 KB |
Output is correct |
26 |
Correct |
4 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
5036 KB |
Output is correct |
28 |
Correct |
3 ms |
5040 KB |
Output is correct |
29 |
Correct |
3 ms |
4948 KB |
Output is correct |
30 |
Correct |
538 ms |
87700 KB |
Output is correct |
31 |
Correct |
323 ms |
84456 KB |
Output is correct |
32 |
Correct |
454 ms |
88848 KB |
Output is correct |
33 |
Correct |
464 ms |
86180 KB |
Output is correct |
34 |
Correct |
363 ms |
85948 KB |
Output is correct |
35 |
Correct |
349 ms |
86452 KB |
Output is correct |
36 |
Correct |
239 ms |
86820 KB |
Output is correct |
37 |
Correct |
608 ms |
91844 KB |
Output is correct |
38 |
Correct |
408 ms |
88392 KB |
Output is correct |
39 |
Correct |
571 ms |
87656 KB |
Output is correct |
40 |
Correct |
364 ms |
96296 KB |
Output is correct |
41 |
Correct |
263 ms |
96724 KB |
Output is correct |
42 |
Correct |
246 ms |
97160 KB |
Output is correct |
43 |
Correct |
238 ms |
96512 KB |
Output is correct |
44 |
Correct |
256 ms |
96960 KB |
Output is correct |
45 |
Correct |
325 ms |
97540 KB |
Output is correct |
46 |
Correct |
3 ms |
4948 KB |
Output is correct |
47 |
Correct |
3 ms |
4948 KB |
Output is correct |
48 |
Correct |
4 ms |
4948 KB |
Output is correct |
49 |
Correct |
4 ms |
5040 KB |
Output is correct |
50 |
Correct |
4 ms |
5036 KB |
Output is correct |
51 |
Correct |
4 ms |
4948 KB |
Output is correct |
52 |
Correct |
572 ms |
95816 KB |
Output is correct |
53 |
Correct |
359 ms |
96440 KB |
Output is correct |
54 |
Correct |
534 ms |
100232 KB |
Output is correct |
55 |
Correct |
464 ms |
96156 KB |
Output is correct |
56 |
Correct |
319 ms |
96168 KB |
Output is correct |
57 |
Correct |
366 ms |
95920 KB |
Output is correct |
58 |
Correct |
277 ms |
96960 KB |
Output is correct |
59 |
Correct |
605 ms |
98972 KB |
Output is correct |
60 |
Correct |
394 ms |
100296 KB |
Output is correct |
61 |
Correct |
620 ms |
95796 KB |
Output is correct |
62 |
Correct |
351 ms |
96508 KB |
Output is correct |
63 |
Correct |
3 ms |
4948 KB |
Output is correct |
64 |
Correct |
3 ms |
4948 KB |
Output is correct |
65 |
Correct |
3 ms |
4948 KB |
Output is correct |
66 |
Correct |
3 ms |
4948 KB |
Output is correct |
67 |
Correct |
3 ms |
4948 KB |
Output is correct |
68 |
Correct |
4 ms |
4948 KB |
Output is correct |
69 |
Correct |
4 ms |
5032 KB |
Output is correct |
70 |
Correct |
4 ms |
5032 KB |
Output is correct |
71 |
Correct |
3 ms |
4948 KB |
Output is correct |
72 |
Correct |
3 ms |
4948 KB |
Output is correct |
73 |
Correct |
3 ms |
4948 KB |
Output is correct |
74 |
Correct |
3 ms |
4948 KB |
Output is correct |
75 |
Correct |
3 ms |
5036 KB |
Output is correct |
76 |
Correct |
3 ms |
5036 KB |
Output is correct |
77 |
Correct |
4 ms |
4948 KB |
Output is correct |
78 |
Correct |
3 ms |
4948 KB |
Output is correct |
79 |
Correct |
701 ms |
89244 KB |
Output is correct |
80 |
Correct |
682 ms |
87404 KB |
Output is correct |
81 |
Correct |
524 ms |
87876 KB |
Output is correct |
82 |
Correct |
536 ms |
84640 KB |
Output is correct |
83 |
Correct |
362 ms |
84604 KB |
Output is correct |
84 |
Correct |
329 ms |
84768 KB |
Output is correct |
85 |
Correct |
251 ms |
85232 KB |
Output is correct |
86 |
Correct |
569 ms |
88132 KB |
Output is correct |
87 |
Correct |
774 ms |
88112 KB |
Output is correct |
88 |
Correct |
597 ms |
84916 KB |
Output is correct |
89 |
Correct |
616 ms |
84428 KB |
Output is correct |
90 |
Correct |
381 ms |
85112 KB |
Output is correct |
91 |
Correct |
408 ms |
85520 KB |
Output is correct |
92 |
Correct |
3 ms |
4948 KB |
Output is correct |
93 |
Correct |
3 ms |
4948 KB |
Output is correct |
94 |
Correct |
3 ms |
4948 KB |
Output is correct |
95 |
Correct |
3 ms |
4948 KB |
Output is correct |
96 |
Correct |
3 ms |
4948 KB |
Output is correct |
97 |
Correct |
3 ms |
4948 KB |
Output is correct |
98 |
Correct |
620 ms |
90424 KB |
Output is correct |
99 |
Correct |
814 ms |
96272 KB |
Output is correct |
100 |
Correct |
553 ms |
97208 KB |
Output is correct |
101 |
Correct |
556 ms |
94852 KB |
Output is correct |
102 |
Correct |
403 ms |
95004 KB |
Output is correct |
103 |
Correct |
383 ms |
94856 KB |
Output is correct |
104 |
Correct |
262 ms |
94956 KB |
Output is correct |
105 |
Correct |
600 ms |
99560 KB |
Output is correct |
106 |
Correct |
728 ms |
98028 KB |
Output is correct |
107 |
Correct |
556 ms |
95664 KB |
Output is correct |
108 |
Correct |
632 ms |
93956 KB |
Output is correct |
109 |
Correct |
468 ms |
94680 KB |
Output is correct |
110 |
Correct |
408 ms |
95320 KB |
Output is correct |
111 |
Correct |
3 ms |
5036 KB |
Output is correct |
112 |
Correct |
3 ms |
4948 KB |
Output is correct |
113 |
Correct |
3 ms |
4948 KB |
Output is correct |
114 |
Correct |
3 ms |
4948 KB |
Output is correct |
115 |
Correct |
3 ms |
5036 KB |
Output is correct |
116 |
Correct |
557 ms |
94032 KB |
Output is correct |
117 |
Correct |
612 ms |
96576 KB |
Output is correct |
118 |
Correct |
549 ms |
100200 KB |
Output is correct |
119 |
Correct |
551 ms |
96204 KB |
Output is correct |
120 |
Correct |
423 ms |
96000 KB |
Output is correct |
121 |
Correct |
403 ms |
96588 KB |
Output is correct |
122 |
Correct |
310 ms |
96832 KB |
Output is correct |
123 |
Correct |
602 ms |
99400 KB |
Output is correct |
124 |
Correct |
772 ms |
98868 KB |
Output is correct |
125 |
Correct |
537 ms |
95036 KB |
Output is correct |
126 |
Correct |
623 ms |
96420 KB |
Output is correct |
127 |
Correct |
729 ms |
96880 KB |
Output is correct |
128 |
Correct |
582 ms |
97584 KB |
Output is correct |
129 |
Correct |
550 ms |
98008 KB |
Output is correct |