#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;
template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;
#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;
const int N = 2e5 + 50, D = 40;
vector<int> g[N];
int p[N];
ll h[N][D + 1];
void dfs(int u = 0, int parent = -1) {
p[u] = parent;
for (int v : g[u]) {
if (v != parent) {
dfs(v, u);
}
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, modulo;
cin >> n >> modulo;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
u += D, v += D;
g[--u].push_back(--v);
g[v].push_back(u);
}
for (int i = 1; i <= D; ++i) {
g[i].push_back(i - 1);
g[i - 1].push_back(i);
}
dfs();
fill(h[0], h[N], 1);
for (int i = 0; i < n; ++i) {
cin >> h[i + D][D];
}
int queries;
cin >> queries;
while (queries--) {
int type;
cin >> type;
if (type == 1) {
int u, d, w;
cin >> u >> d >> w;
u += D - 1;
for (int i = 0; i <= d; ++i) {
(h[u][D - d + i] *= w) %= modulo;
u = p[u];
}
} else {
int u;
cin >> u;
u += D - 1;
ll ans = 1;
for (int i = 0; i <= D; ++i) {
(ans *= h[u][D - i]) %= modulo;
if (i != D) {
(ans *= h[u][D - i - 1]) %= modulo;
}
u = p[u];
}
cout << ans << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
69160 KB |
Output is correct |
2 |
Correct |
27 ms |
69164 KB |
Output is correct |
3 |
Correct |
28 ms |
69204 KB |
Output is correct |
4 |
Correct |
30 ms |
69204 KB |
Output is correct |
5 |
Correct |
29 ms |
69180 KB |
Output is correct |
6 |
Correct |
28 ms |
69268 KB |
Output is correct |
7 |
Correct |
29 ms |
69288 KB |
Output is correct |
8 |
Correct |
28 ms |
69284 KB |
Output is correct |
9 |
Correct |
30 ms |
69144 KB |
Output is correct |
10 |
Correct |
27 ms |
69276 KB |
Output is correct |
11 |
Correct |
28 ms |
69196 KB |
Output is correct |
12 |
Correct |
28 ms |
69116 KB |
Output is correct |
13 |
Correct |
28 ms |
69204 KB |
Output is correct |
14 |
Correct |
29 ms |
69184 KB |
Output is correct |
15 |
Correct |
28 ms |
69152 KB |
Output is correct |
16 |
Correct |
27 ms |
69144 KB |
Output is correct |
17 |
Correct |
31 ms |
69180 KB |
Output is correct |
18 |
Correct |
28 ms |
69120 KB |
Output is correct |
19 |
Correct |
27 ms |
69204 KB |
Output is correct |
20 |
Correct |
27 ms |
69196 KB |
Output is correct |
21 |
Correct |
28 ms |
69236 KB |
Output is correct |
22 |
Correct |
31 ms |
69204 KB |
Output is correct |
23 |
Correct |
30 ms |
69136 KB |
Output is correct |
24 |
Correct |
28 ms |
69152 KB |
Output is correct |
25 |
Correct |
29 ms |
69148 KB |
Output is correct |
26 |
Correct |
28 ms |
69216 KB |
Output is correct |
27 |
Correct |
29 ms |
69116 KB |
Output is correct |
28 |
Correct |
28 ms |
69144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
69144 KB |
Output is correct |
2 |
Correct |
530 ms |
87832 KB |
Output is correct |
3 |
Correct |
333 ms |
88316 KB |
Output is correct |
4 |
Correct |
467 ms |
90636 KB |
Output is correct |
5 |
Correct |
442 ms |
87640 KB |
Output is correct |
6 |
Correct |
370 ms |
85452 KB |
Output is correct |
7 |
Correct |
379 ms |
88172 KB |
Output is correct |
8 |
Correct |
333 ms |
86256 KB |
Output is correct |
9 |
Correct |
600 ms |
92040 KB |
Output is correct |
10 |
Correct |
388 ms |
92076 KB |
Output is correct |
11 |
Correct |
518 ms |
86408 KB |
Output is correct |
12 |
Correct |
340 ms |
84872 KB |
Output is correct |
13 |
Correct |
250 ms |
88812 KB |
Output is correct |
14 |
Correct |
258 ms |
89152 KB |
Output is correct |
15 |
Correct |
239 ms |
78880 KB |
Output is correct |
16 |
Correct |
264 ms |
83312 KB |
Output is correct |
17 |
Correct |
262 ms |
84316 KB |
Output is correct |
18 |
Correct |
28 ms |
69240 KB |
Output is correct |
19 |
Correct |
29 ms |
69140 KB |
Output is correct |
20 |
Correct |
29 ms |
69124 KB |
Output is correct |
21 |
Correct |
32 ms |
69216 KB |
Output is correct |
22 |
Correct |
28 ms |
69204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
69144 KB |
Output is correct |
2 |
Correct |
530 ms |
87832 KB |
Output is correct |
3 |
Correct |
333 ms |
88316 KB |
Output is correct |
4 |
Correct |
467 ms |
90636 KB |
Output is correct |
5 |
Correct |
442 ms |
87640 KB |
Output is correct |
6 |
Correct |
370 ms |
85452 KB |
Output is correct |
7 |
Correct |
379 ms |
88172 KB |
Output is correct |
8 |
Correct |
333 ms |
86256 KB |
Output is correct |
9 |
Correct |
600 ms |
92040 KB |
Output is correct |
10 |
Correct |
388 ms |
92076 KB |
Output is correct |
11 |
Correct |
518 ms |
86408 KB |
Output is correct |
12 |
Correct |
340 ms |
84872 KB |
Output is correct |
13 |
Correct |
250 ms |
88812 KB |
Output is correct |
14 |
Correct |
258 ms |
89152 KB |
Output is correct |
15 |
Correct |
239 ms |
78880 KB |
Output is correct |
16 |
Correct |
264 ms |
83312 KB |
Output is correct |
17 |
Correct |
262 ms |
84316 KB |
Output is correct |
18 |
Correct |
28 ms |
69240 KB |
Output is correct |
19 |
Correct |
29 ms |
69140 KB |
Output is correct |
20 |
Correct |
29 ms |
69124 KB |
Output is correct |
21 |
Correct |
32 ms |
69216 KB |
Output is correct |
22 |
Correct |
28 ms |
69204 KB |
Output is correct |
23 |
Correct |
29 ms |
69148 KB |
Output is correct |
24 |
Correct |
544 ms |
87884 KB |
Output is correct |
25 |
Correct |
347 ms |
87276 KB |
Output is correct |
26 |
Correct |
505 ms |
92260 KB |
Output is correct |
27 |
Correct |
485 ms |
87560 KB |
Output is correct |
28 |
Correct |
416 ms |
88012 KB |
Output is correct |
29 |
Correct |
392 ms |
87960 KB |
Output is correct |
30 |
Correct |
340 ms |
88360 KB |
Output is correct |
31 |
Correct |
625 ms |
90620 KB |
Output is correct |
32 |
Correct |
374 ms |
91592 KB |
Output is correct |
33 |
Correct |
555 ms |
87752 KB |
Output is correct |
34 |
Correct |
368 ms |
87824 KB |
Output is correct |
35 |
Correct |
28 ms |
69180 KB |
Output is correct |
36 |
Correct |
29 ms |
69196 KB |
Output is correct |
37 |
Correct |
29 ms |
69216 KB |
Output is correct |
38 |
Correct |
30 ms |
69184 KB |
Output is correct |
39 |
Correct |
28 ms |
69196 KB |
Output is correct |
40 |
Correct |
28 ms |
69204 KB |
Output is correct |
41 |
Correct |
29 ms |
69200 KB |
Output is correct |
42 |
Correct |
29 ms |
69124 KB |
Output is correct |
43 |
Correct |
28 ms |
69196 KB |
Output is correct |
44 |
Correct |
32 ms |
69156 KB |
Output is correct |
45 |
Correct |
30 ms |
69204 KB |
Output is correct |
46 |
Correct |
29 ms |
69148 KB |
Output is correct |
47 |
Correct |
29 ms |
69192 KB |
Output is correct |
48 |
Correct |
28 ms |
69112 KB |
Output is correct |
49 |
Correct |
29 ms |
69148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
69196 KB |
Output is correct |
2 |
Correct |
638 ms |
88708 KB |
Output is correct |
3 |
Correct |
613 ms |
88188 KB |
Output is correct |
4 |
Correct |
562 ms |
88052 KB |
Output is correct |
5 |
Correct |
485 ms |
84944 KB |
Output is correct |
6 |
Correct |
403 ms |
84756 KB |
Output is correct |
7 |
Correct |
379 ms |
85076 KB |
Output is correct |
8 |
Correct |
338 ms |
85412 KB |
Output is correct |
9 |
Correct |
703 ms |
88032 KB |
Output is correct |
10 |
Correct |
613 ms |
89008 KB |
Output is correct |
11 |
Correct |
543 ms |
84536 KB |
Output is correct |
12 |
Correct |
542 ms |
85052 KB |
Output is correct |
13 |
Correct |
358 ms |
85672 KB |
Output is correct |
14 |
Correct |
378 ms |
86764 KB |
Output is correct |
15 |
Correct |
30 ms |
69196 KB |
Output is correct |
16 |
Correct |
30 ms |
69132 KB |
Output is correct |
17 |
Correct |
29 ms |
69204 KB |
Output is correct |
18 |
Correct |
28 ms |
69220 KB |
Output is correct |
19 |
Correct |
33 ms |
69196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
69112 KB |
Output is correct |
2 |
Correct |
648 ms |
89552 KB |
Output is correct |
3 |
Correct |
621 ms |
87792 KB |
Output is correct |
4 |
Correct |
584 ms |
88836 KB |
Output is correct |
5 |
Correct |
536 ms |
86360 KB |
Output is correct |
6 |
Correct |
438 ms |
86612 KB |
Output is correct |
7 |
Correct |
409 ms |
86392 KB |
Output is correct |
8 |
Correct |
360 ms |
86672 KB |
Output is correct |
9 |
Correct |
646 ms |
91460 KB |
Output is correct |
10 |
Correct |
623 ms |
89308 KB |
Output is correct |
11 |
Correct |
581 ms |
87196 KB |
Output is correct |
12 |
Correct |
541 ms |
85456 KB |
Output is correct |
13 |
Correct |
375 ms |
86592 KB |
Output is correct |
14 |
Correct |
436 ms |
87060 KB |
Output is correct |
15 |
Correct |
30 ms |
69188 KB |
Output is correct |
16 |
Correct |
30 ms |
69192 KB |
Output is correct |
17 |
Correct |
29 ms |
69224 KB |
Output is correct |
18 |
Correct |
31 ms |
69132 KB |
Output is correct |
19 |
Correct |
33 ms |
69196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
69160 KB |
Output is correct |
2 |
Correct |
27 ms |
69164 KB |
Output is correct |
3 |
Correct |
28 ms |
69204 KB |
Output is correct |
4 |
Correct |
30 ms |
69204 KB |
Output is correct |
5 |
Correct |
29 ms |
69180 KB |
Output is correct |
6 |
Correct |
28 ms |
69268 KB |
Output is correct |
7 |
Correct |
29 ms |
69288 KB |
Output is correct |
8 |
Correct |
28 ms |
69284 KB |
Output is correct |
9 |
Correct |
30 ms |
69144 KB |
Output is correct |
10 |
Correct |
27 ms |
69276 KB |
Output is correct |
11 |
Correct |
28 ms |
69196 KB |
Output is correct |
12 |
Correct |
28 ms |
69116 KB |
Output is correct |
13 |
Correct |
28 ms |
69204 KB |
Output is correct |
14 |
Correct |
29 ms |
69184 KB |
Output is correct |
15 |
Correct |
28 ms |
69152 KB |
Output is correct |
16 |
Correct |
27 ms |
69144 KB |
Output is correct |
17 |
Correct |
31 ms |
69180 KB |
Output is correct |
18 |
Correct |
28 ms |
69120 KB |
Output is correct |
19 |
Correct |
27 ms |
69204 KB |
Output is correct |
20 |
Correct |
27 ms |
69196 KB |
Output is correct |
21 |
Correct |
28 ms |
69236 KB |
Output is correct |
22 |
Correct |
31 ms |
69204 KB |
Output is correct |
23 |
Correct |
30 ms |
69136 KB |
Output is correct |
24 |
Correct |
28 ms |
69152 KB |
Output is correct |
25 |
Correct |
29 ms |
69148 KB |
Output is correct |
26 |
Correct |
28 ms |
69216 KB |
Output is correct |
27 |
Correct |
29 ms |
69116 KB |
Output is correct |
28 |
Correct |
28 ms |
69144 KB |
Output is correct |
29 |
Correct |
27 ms |
69144 KB |
Output is correct |
30 |
Correct |
530 ms |
87832 KB |
Output is correct |
31 |
Correct |
333 ms |
88316 KB |
Output is correct |
32 |
Correct |
467 ms |
90636 KB |
Output is correct |
33 |
Correct |
442 ms |
87640 KB |
Output is correct |
34 |
Correct |
370 ms |
85452 KB |
Output is correct |
35 |
Correct |
379 ms |
88172 KB |
Output is correct |
36 |
Correct |
333 ms |
86256 KB |
Output is correct |
37 |
Correct |
600 ms |
92040 KB |
Output is correct |
38 |
Correct |
388 ms |
92076 KB |
Output is correct |
39 |
Correct |
518 ms |
86408 KB |
Output is correct |
40 |
Correct |
340 ms |
84872 KB |
Output is correct |
41 |
Correct |
250 ms |
88812 KB |
Output is correct |
42 |
Correct |
258 ms |
89152 KB |
Output is correct |
43 |
Correct |
239 ms |
78880 KB |
Output is correct |
44 |
Correct |
264 ms |
83312 KB |
Output is correct |
45 |
Correct |
262 ms |
84316 KB |
Output is correct |
46 |
Correct |
28 ms |
69240 KB |
Output is correct |
47 |
Correct |
29 ms |
69140 KB |
Output is correct |
48 |
Correct |
29 ms |
69124 KB |
Output is correct |
49 |
Correct |
32 ms |
69216 KB |
Output is correct |
50 |
Correct |
28 ms |
69204 KB |
Output is correct |
51 |
Correct |
29 ms |
69148 KB |
Output is correct |
52 |
Correct |
544 ms |
87884 KB |
Output is correct |
53 |
Correct |
347 ms |
87276 KB |
Output is correct |
54 |
Correct |
505 ms |
92260 KB |
Output is correct |
55 |
Correct |
485 ms |
87560 KB |
Output is correct |
56 |
Correct |
416 ms |
88012 KB |
Output is correct |
57 |
Correct |
392 ms |
87960 KB |
Output is correct |
58 |
Correct |
340 ms |
88360 KB |
Output is correct |
59 |
Correct |
625 ms |
90620 KB |
Output is correct |
60 |
Correct |
374 ms |
91592 KB |
Output is correct |
61 |
Correct |
555 ms |
87752 KB |
Output is correct |
62 |
Correct |
368 ms |
87824 KB |
Output is correct |
63 |
Correct |
28 ms |
69180 KB |
Output is correct |
64 |
Correct |
29 ms |
69196 KB |
Output is correct |
65 |
Correct |
29 ms |
69216 KB |
Output is correct |
66 |
Correct |
30 ms |
69184 KB |
Output is correct |
67 |
Correct |
28 ms |
69196 KB |
Output is correct |
68 |
Correct |
28 ms |
69204 KB |
Output is correct |
69 |
Correct |
29 ms |
69200 KB |
Output is correct |
70 |
Correct |
29 ms |
69124 KB |
Output is correct |
71 |
Correct |
28 ms |
69196 KB |
Output is correct |
72 |
Correct |
32 ms |
69156 KB |
Output is correct |
73 |
Correct |
30 ms |
69204 KB |
Output is correct |
74 |
Correct |
29 ms |
69148 KB |
Output is correct |
75 |
Correct |
29 ms |
69192 KB |
Output is correct |
76 |
Correct |
28 ms |
69112 KB |
Output is correct |
77 |
Correct |
29 ms |
69148 KB |
Output is correct |
78 |
Correct |
28 ms |
69196 KB |
Output is correct |
79 |
Correct |
638 ms |
88708 KB |
Output is correct |
80 |
Correct |
613 ms |
88188 KB |
Output is correct |
81 |
Correct |
562 ms |
88052 KB |
Output is correct |
82 |
Correct |
485 ms |
84944 KB |
Output is correct |
83 |
Correct |
403 ms |
84756 KB |
Output is correct |
84 |
Correct |
379 ms |
85076 KB |
Output is correct |
85 |
Correct |
338 ms |
85412 KB |
Output is correct |
86 |
Correct |
703 ms |
88032 KB |
Output is correct |
87 |
Correct |
613 ms |
89008 KB |
Output is correct |
88 |
Correct |
543 ms |
84536 KB |
Output is correct |
89 |
Correct |
542 ms |
85052 KB |
Output is correct |
90 |
Correct |
358 ms |
85672 KB |
Output is correct |
91 |
Correct |
378 ms |
86764 KB |
Output is correct |
92 |
Correct |
30 ms |
69196 KB |
Output is correct |
93 |
Correct |
30 ms |
69132 KB |
Output is correct |
94 |
Correct |
29 ms |
69204 KB |
Output is correct |
95 |
Correct |
28 ms |
69220 KB |
Output is correct |
96 |
Correct |
33 ms |
69196 KB |
Output is correct |
97 |
Correct |
31 ms |
69112 KB |
Output is correct |
98 |
Correct |
648 ms |
89552 KB |
Output is correct |
99 |
Correct |
621 ms |
87792 KB |
Output is correct |
100 |
Correct |
584 ms |
88836 KB |
Output is correct |
101 |
Correct |
536 ms |
86360 KB |
Output is correct |
102 |
Correct |
438 ms |
86612 KB |
Output is correct |
103 |
Correct |
409 ms |
86392 KB |
Output is correct |
104 |
Correct |
360 ms |
86672 KB |
Output is correct |
105 |
Correct |
646 ms |
91460 KB |
Output is correct |
106 |
Correct |
623 ms |
89308 KB |
Output is correct |
107 |
Correct |
581 ms |
87196 KB |
Output is correct |
108 |
Correct |
541 ms |
85456 KB |
Output is correct |
109 |
Correct |
375 ms |
86592 KB |
Output is correct |
110 |
Correct |
436 ms |
87060 KB |
Output is correct |
111 |
Correct |
30 ms |
69188 KB |
Output is correct |
112 |
Correct |
30 ms |
69192 KB |
Output is correct |
113 |
Correct |
29 ms |
69224 KB |
Output is correct |
114 |
Correct |
31 ms |
69132 KB |
Output is correct |
115 |
Correct |
33 ms |
69196 KB |
Output is correct |
116 |
Correct |
607 ms |
85588 KB |
Output is correct |
117 |
Correct |
589 ms |
88428 KB |
Output is correct |
118 |
Correct |
586 ms |
91384 KB |
Output is correct |
119 |
Correct |
531 ms |
87884 KB |
Output is correct |
120 |
Correct |
455 ms |
87124 KB |
Output is correct |
121 |
Correct |
454 ms |
88140 KB |
Output is correct |
122 |
Correct |
394 ms |
88248 KB |
Output is correct |
123 |
Correct |
655 ms |
91248 KB |
Output is correct |
124 |
Correct |
641 ms |
90712 KB |
Output is correct |
125 |
Correct |
608 ms |
86392 KB |
Output is correct |
126 |
Correct |
602 ms |
88032 KB |
Output is correct |
127 |
Correct |
624 ms |
88584 KB |
Output is correct |
128 |
Correct |
427 ms |
85824 KB |
Output is correct |
129 |
Correct |
422 ms |
81656 KB |
Output is correct |