#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 3e5 + 50;
vector <int> ed[N];
int p[N];
ll mul[N][41], l;
ll h[N];
void dfs(int u, int v) {
p[u] = v;
for (int i = 0; i < 41; i++)
mul[u][i] = 1;
for (auto x : ed[u]) {
if (x == v)
continue;
dfs(x, u);
}
}
void upd(int x, int d, ll w) {
for (int i = 0; i <= d; i++) {
mul[x][d - i] = (mul[x][d - i] * w) % l;
x = p[x];
}
}
ll get(int x) {
ll pr = h[x];
for (int i = 0; i < 41; i++) {
pr = (pr * mul[x][i]) % l;
if (i + 1 < 41)
pr = (pr * mul[x][i + 1]) % l;
x = p[x];
}
return pr;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n >> l;
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
a += 40;
b += 40;
ed[a].pb(b);
ed[b].pb(a);
}
for (int i = 1; i <= 40; i++) {
ed[i].pb(i + 1);
ed[i + 1].pb(i);
}
for (int i = 41; i <= n + 40; i++)
cin >> h[i];
dfs(1, 1);
int q;
cin >> q;
for (int i = 1; i <= q; i++) {
int t;
cin >> t;
if (t == 1) {
ll x, d, w;
cin >> x >> d >> w;
x += 40;
upd(x, d, w);
} else {
int x;
cin >> x;
x += 40;
cout << get(x) << '\n';
}
}
return 0;
}
/*
10 10
10 -8
7 2
7 -8
-3 -6
-2 1
-8 6
8 -1
2 4
6 -6
2 -1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12632 KB |
Output is correct |
2 |
Correct |
3 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12828 KB |
Output is correct |
5 |
Correct |
6 ms |
12828 KB |
Output is correct |
6 |
Correct |
3 ms |
12768 KB |
Output is correct |
7 |
Correct |
5 ms |
12636 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
3 ms |
12664 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12760 KB |
Output is correct |
16 |
Correct |
4 ms |
12636 KB |
Output is correct |
17 |
Correct |
4 ms |
12636 KB |
Output is correct |
18 |
Correct |
4 ms |
12636 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
3 ms |
12636 KB |
Output is correct |
22 |
Correct |
2 ms |
12636 KB |
Output is correct |
23 |
Correct |
3 ms |
12636 KB |
Output is correct |
24 |
Correct |
3 ms |
12892 KB |
Output is correct |
25 |
Correct |
3 ms |
12636 KB |
Output is correct |
26 |
Correct |
3 ms |
12760 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
3 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
495 ms |
96572 KB |
Output is correct |
3 |
Correct |
329 ms |
97224 KB |
Output is correct |
4 |
Correct |
526 ms |
101324 KB |
Output is correct |
5 |
Correct |
403 ms |
95680 KB |
Output is correct |
6 |
Correct |
348 ms |
94980 KB |
Output is correct |
7 |
Correct |
403 ms |
95944 KB |
Output is correct |
8 |
Correct |
322 ms |
97688 KB |
Output is correct |
9 |
Correct |
661 ms |
104244 KB |
Output is correct |
10 |
Correct |
331 ms |
104156 KB |
Output is correct |
11 |
Correct |
483 ms |
95600 KB |
Output is correct |
12 |
Correct |
365 ms |
95876 KB |
Output is correct |
13 |
Correct |
224 ms |
97440 KB |
Output is correct |
14 |
Correct |
233 ms |
96452 KB |
Output is correct |
15 |
Correct |
223 ms |
95824 KB |
Output is correct |
16 |
Correct |
240 ms |
96444 KB |
Output is correct |
17 |
Correct |
253 ms |
98132 KB |
Output is correct |
18 |
Correct |
4 ms |
12632 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
4 ms |
12636 KB |
Output is correct |
21 |
Correct |
4 ms |
12632 KB |
Output is correct |
22 |
Correct |
3 ms |
12632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
495 ms |
96572 KB |
Output is correct |
3 |
Correct |
329 ms |
97224 KB |
Output is correct |
4 |
Correct |
526 ms |
101324 KB |
Output is correct |
5 |
Correct |
403 ms |
95680 KB |
Output is correct |
6 |
Correct |
348 ms |
94980 KB |
Output is correct |
7 |
Correct |
403 ms |
95944 KB |
Output is correct |
8 |
Correct |
322 ms |
97688 KB |
Output is correct |
9 |
Correct |
661 ms |
104244 KB |
Output is correct |
10 |
Correct |
331 ms |
104156 KB |
Output is correct |
11 |
Correct |
483 ms |
95600 KB |
Output is correct |
12 |
Correct |
365 ms |
95876 KB |
Output is correct |
13 |
Correct |
224 ms |
97440 KB |
Output is correct |
14 |
Correct |
233 ms |
96452 KB |
Output is correct |
15 |
Correct |
223 ms |
95824 KB |
Output is correct |
16 |
Correct |
240 ms |
96444 KB |
Output is correct |
17 |
Correct |
253 ms |
98132 KB |
Output is correct |
18 |
Correct |
4 ms |
12632 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
4 ms |
12636 KB |
Output is correct |
21 |
Correct |
4 ms |
12632 KB |
Output is correct |
22 |
Correct |
3 ms |
12632 KB |
Output is correct |
23 |
Correct |
2 ms |
12636 KB |
Output is correct |
24 |
Correct |
550 ms |
95300 KB |
Output is correct |
25 |
Correct |
318 ms |
95992 KB |
Output is correct |
26 |
Correct |
493 ms |
105488 KB |
Output is correct |
27 |
Correct |
407 ms |
96944 KB |
Output is correct |
28 |
Correct |
362 ms |
96984 KB |
Output is correct |
29 |
Correct |
423 ms |
96640 KB |
Output is correct |
30 |
Correct |
328 ms |
96460 KB |
Output is correct |
31 |
Correct |
715 ms |
101836 KB |
Output is correct |
32 |
Correct |
404 ms |
104128 KB |
Output is correct |
33 |
Correct |
522 ms |
96804 KB |
Output is correct |
34 |
Correct |
336 ms |
96016 KB |
Output is correct |
35 |
Correct |
3 ms |
12632 KB |
Output is correct |
36 |
Correct |
3 ms |
12636 KB |
Output is correct |
37 |
Correct |
3 ms |
12636 KB |
Output is correct |
38 |
Correct |
4 ms |
12636 KB |
Output is correct |
39 |
Correct |
3 ms |
12636 KB |
Output is correct |
40 |
Correct |
3 ms |
12636 KB |
Output is correct |
41 |
Correct |
3 ms |
12756 KB |
Output is correct |
42 |
Correct |
3 ms |
12636 KB |
Output is correct |
43 |
Correct |
3 ms |
12636 KB |
Output is correct |
44 |
Correct |
4 ms |
12636 KB |
Output is correct |
45 |
Correct |
3 ms |
12632 KB |
Output is correct |
46 |
Correct |
3 ms |
12636 KB |
Output is correct |
47 |
Correct |
3 ms |
12636 KB |
Output is correct |
48 |
Correct |
4 ms |
12636 KB |
Output is correct |
49 |
Correct |
2 ms |
12764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12636 KB |
Output is correct |
2 |
Correct |
710 ms |
101100 KB |
Output is correct |
3 |
Correct |
566 ms |
101456 KB |
Output is correct |
4 |
Correct |
553 ms |
99572 KB |
Output is correct |
5 |
Correct |
508 ms |
92788 KB |
Output is correct |
6 |
Correct |
390 ms |
92676 KB |
Output is correct |
7 |
Correct |
386 ms |
92692 KB |
Output is correct |
8 |
Correct |
333 ms |
93564 KB |
Output is correct |
9 |
Correct |
704 ms |
98520 KB |
Output is correct |
10 |
Correct |
562 ms |
101120 KB |
Output is correct |
11 |
Correct |
510 ms |
92080 KB |
Output is correct |
12 |
Correct |
514 ms |
94688 KB |
Output is correct |
13 |
Correct |
404 ms |
93888 KB |
Output is correct |
14 |
Correct |
357 ms |
94436 KB |
Output is correct |
15 |
Correct |
3 ms |
12632 KB |
Output is correct |
16 |
Correct |
3 ms |
12708 KB |
Output is correct |
17 |
Correct |
3 ms |
12636 KB |
Output is correct |
18 |
Correct |
3 ms |
12636 KB |
Output is correct |
19 |
Correct |
3 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
691 ms |
100904 KB |
Output is correct |
3 |
Correct |
648 ms |
97876 KB |
Output is correct |
4 |
Correct |
574 ms |
99904 KB |
Output is correct |
5 |
Correct |
517 ms |
95492 KB |
Output is correct |
6 |
Correct |
399 ms |
94220 KB |
Output is correct |
7 |
Correct |
380 ms |
93984 KB |
Output is correct |
8 |
Correct |
332 ms |
94404 KB |
Output is correct |
9 |
Correct |
686 ms |
103200 KB |
Output is correct |
10 |
Correct |
587 ms |
101856 KB |
Output is correct |
11 |
Correct |
495 ms |
94884 KB |
Output is correct |
12 |
Correct |
472 ms |
93512 KB |
Output is correct |
13 |
Correct |
349 ms |
94432 KB |
Output is correct |
14 |
Correct |
373 ms |
96084 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
3 ms |
12636 KB |
Output is correct |
17 |
Correct |
3 ms |
12756 KB |
Output is correct |
18 |
Correct |
3 ms |
12644 KB |
Output is correct |
19 |
Correct |
3 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12632 KB |
Output is correct |
2 |
Correct |
3 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12828 KB |
Output is correct |
5 |
Correct |
6 ms |
12828 KB |
Output is correct |
6 |
Correct |
3 ms |
12768 KB |
Output is correct |
7 |
Correct |
5 ms |
12636 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
3 ms |
12664 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12760 KB |
Output is correct |
16 |
Correct |
4 ms |
12636 KB |
Output is correct |
17 |
Correct |
4 ms |
12636 KB |
Output is correct |
18 |
Correct |
4 ms |
12636 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
3 ms |
12636 KB |
Output is correct |
22 |
Correct |
2 ms |
12636 KB |
Output is correct |
23 |
Correct |
3 ms |
12636 KB |
Output is correct |
24 |
Correct |
3 ms |
12892 KB |
Output is correct |
25 |
Correct |
3 ms |
12636 KB |
Output is correct |
26 |
Correct |
3 ms |
12760 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
3 ms |
12636 KB |
Output is correct |
29 |
Correct |
2 ms |
12636 KB |
Output is correct |
30 |
Correct |
495 ms |
96572 KB |
Output is correct |
31 |
Correct |
329 ms |
97224 KB |
Output is correct |
32 |
Correct |
526 ms |
101324 KB |
Output is correct |
33 |
Correct |
403 ms |
95680 KB |
Output is correct |
34 |
Correct |
348 ms |
94980 KB |
Output is correct |
35 |
Correct |
403 ms |
95944 KB |
Output is correct |
36 |
Correct |
322 ms |
97688 KB |
Output is correct |
37 |
Correct |
661 ms |
104244 KB |
Output is correct |
38 |
Correct |
331 ms |
104156 KB |
Output is correct |
39 |
Correct |
483 ms |
95600 KB |
Output is correct |
40 |
Correct |
365 ms |
95876 KB |
Output is correct |
41 |
Correct |
224 ms |
97440 KB |
Output is correct |
42 |
Correct |
233 ms |
96452 KB |
Output is correct |
43 |
Correct |
223 ms |
95824 KB |
Output is correct |
44 |
Correct |
240 ms |
96444 KB |
Output is correct |
45 |
Correct |
253 ms |
98132 KB |
Output is correct |
46 |
Correct |
4 ms |
12632 KB |
Output is correct |
47 |
Correct |
4 ms |
12636 KB |
Output is correct |
48 |
Correct |
4 ms |
12636 KB |
Output is correct |
49 |
Correct |
4 ms |
12632 KB |
Output is correct |
50 |
Correct |
3 ms |
12632 KB |
Output is correct |
51 |
Correct |
2 ms |
12636 KB |
Output is correct |
52 |
Correct |
550 ms |
95300 KB |
Output is correct |
53 |
Correct |
318 ms |
95992 KB |
Output is correct |
54 |
Correct |
493 ms |
105488 KB |
Output is correct |
55 |
Correct |
407 ms |
96944 KB |
Output is correct |
56 |
Correct |
362 ms |
96984 KB |
Output is correct |
57 |
Correct |
423 ms |
96640 KB |
Output is correct |
58 |
Correct |
328 ms |
96460 KB |
Output is correct |
59 |
Correct |
715 ms |
101836 KB |
Output is correct |
60 |
Correct |
404 ms |
104128 KB |
Output is correct |
61 |
Correct |
522 ms |
96804 KB |
Output is correct |
62 |
Correct |
336 ms |
96016 KB |
Output is correct |
63 |
Correct |
3 ms |
12632 KB |
Output is correct |
64 |
Correct |
3 ms |
12636 KB |
Output is correct |
65 |
Correct |
3 ms |
12636 KB |
Output is correct |
66 |
Correct |
4 ms |
12636 KB |
Output is correct |
67 |
Correct |
3 ms |
12636 KB |
Output is correct |
68 |
Correct |
3 ms |
12636 KB |
Output is correct |
69 |
Correct |
3 ms |
12756 KB |
Output is correct |
70 |
Correct |
3 ms |
12636 KB |
Output is correct |
71 |
Correct |
3 ms |
12636 KB |
Output is correct |
72 |
Correct |
4 ms |
12636 KB |
Output is correct |
73 |
Correct |
3 ms |
12632 KB |
Output is correct |
74 |
Correct |
3 ms |
12636 KB |
Output is correct |
75 |
Correct |
3 ms |
12636 KB |
Output is correct |
76 |
Correct |
4 ms |
12636 KB |
Output is correct |
77 |
Correct |
2 ms |
12764 KB |
Output is correct |
78 |
Correct |
3 ms |
12636 KB |
Output is correct |
79 |
Correct |
710 ms |
101100 KB |
Output is correct |
80 |
Correct |
566 ms |
101456 KB |
Output is correct |
81 |
Correct |
553 ms |
99572 KB |
Output is correct |
82 |
Correct |
508 ms |
92788 KB |
Output is correct |
83 |
Correct |
390 ms |
92676 KB |
Output is correct |
84 |
Correct |
386 ms |
92692 KB |
Output is correct |
85 |
Correct |
333 ms |
93564 KB |
Output is correct |
86 |
Correct |
704 ms |
98520 KB |
Output is correct |
87 |
Correct |
562 ms |
101120 KB |
Output is correct |
88 |
Correct |
510 ms |
92080 KB |
Output is correct |
89 |
Correct |
514 ms |
94688 KB |
Output is correct |
90 |
Correct |
404 ms |
93888 KB |
Output is correct |
91 |
Correct |
357 ms |
94436 KB |
Output is correct |
92 |
Correct |
3 ms |
12632 KB |
Output is correct |
93 |
Correct |
3 ms |
12708 KB |
Output is correct |
94 |
Correct |
3 ms |
12636 KB |
Output is correct |
95 |
Correct |
3 ms |
12636 KB |
Output is correct |
96 |
Correct |
3 ms |
12636 KB |
Output is correct |
97 |
Correct |
2 ms |
12636 KB |
Output is correct |
98 |
Correct |
691 ms |
100904 KB |
Output is correct |
99 |
Correct |
648 ms |
97876 KB |
Output is correct |
100 |
Correct |
574 ms |
99904 KB |
Output is correct |
101 |
Correct |
517 ms |
95492 KB |
Output is correct |
102 |
Correct |
399 ms |
94220 KB |
Output is correct |
103 |
Correct |
380 ms |
93984 KB |
Output is correct |
104 |
Correct |
332 ms |
94404 KB |
Output is correct |
105 |
Correct |
686 ms |
103200 KB |
Output is correct |
106 |
Correct |
587 ms |
101856 KB |
Output is correct |
107 |
Correct |
495 ms |
94884 KB |
Output is correct |
108 |
Correct |
472 ms |
93512 KB |
Output is correct |
109 |
Correct |
349 ms |
94432 KB |
Output is correct |
110 |
Correct |
373 ms |
96084 KB |
Output is correct |
111 |
Correct |
3 ms |
12636 KB |
Output is correct |
112 |
Correct |
3 ms |
12636 KB |
Output is correct |
113 |
Correct |
3 ms |
12756 KB |
Output is correct |
114 |
Correct |
3 ms |
12644 KB |
Output is correct |
115 |
Correct |
3 ms |
12636 KB |
Output is correct |
116 |
Correct |
558 ms |
94548 KB |
Output is correct |
117 |
Correct |
509 ms |
95852 KB |
Output is correct |
118 |
Correct |
635 ms |
104164 KB |
Output is correct |
119 |
Correct |
511 ms |
95652 KB |
Output is correct |
120 |
Correct |
406 ms |
96628 KB |
Output is correct |
121 |
Correct |
428 ms |
97204 KB |
Output is correct |
122 |
Correct |
351 ms |
96196 KB |
Output is correct |
123 |
Correct |
665 ms |
102548 KB |
Output is correct |
124 |
Correct |
582 ms |
101120 KB |
Output is correct |
125 |
Correct |
523 ms |
94372 KB |
Output is correct |
126 |
Correct |
485 ms |
95828 KB |
Output is correct |
127 |
Correct |
503 ms |
96204 KB |
Output is correct |
128 |
Correct |
388 ms |
97084 KB |
Output is correct |
129 |
Correct |
410 ms |
98936 KB |
Output is correct |