#include <bits/stdc++.h>
#define int long long
using namespace std;
const int M = 2e5 + 42, N = 2 * M, T = 19, INF = 1e18 + 42, MOD = 1e9 + 7;
vector<int> adj[M];
int n, l, q, id = 0, h[M], pere[M], prof[M], ch[M][42];
void dfs(int i, int pre, int depth = 0) {
pere[i] = pre;
prof[i] = depth;
for(int j : adj[i])
if(j != pre)
dfs(j, i, depth+1);
}
void update(int i, int d, int prod) {
do {
if(i == 0 || d < 2) {
for(int j = 0; j <= d; j++)
ch[i][j] = ch[i][j] * prod % l;
} else {
ch[i][d] = ch[i][d] * prod % l;
ch[i][d-1] = ch[i][d-1] * prod % l;
}
d--;
i = pere[i];
} while(i != -1 && d >= 0);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> l;
for(int i = 0; i < M; i++)
for(int j = 0; j < 42; j++)
ch[i][j] = 1;
for(int i = 0; i < n-1; i++) {
int a, b; cin >> a >> b;
a--, b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(0, -1);
for(int i = 0; i < n; i++)
cin >> h[i];
cin >> q;
for(int i = 0; i < q; i++) {
int typ; cin >> typ;
if(typ == 1) {
int x, dist, prod;
cin >> x >> dist >> prod;
update(x-1, dist, prod);
} else {
int x;
cin >> x;
int j = x-1, d = 0, ans = h[j];
while(j >= 0 && d < 41) {
ans = ans * ch[j][d] % l;
j = pere[j];
d++;
}
cout << ans << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
70712 KB |
Output is correct |
2 |
Correct |
30 ms |
70676 KB |
Output is correct |
3 |
Correct |
30 ms |
70748 KB |
Output is correct |
4 |
Correct |
30 ms |
70860 KB |
Output is correct |
5 |
Correct |
31 ms |
70868 KB |
Output is correct |
6 |
Correct |
36 ms |
70828 KB |
Output is correct |
7 |
Correct |
30 ms |
70868 KB |
Output is correct |
8 |
Correct |
31 ms |
70816 KB |
Output is correct |
9 |
Correct |
31 ms |
70732 KB |
Output is correct |
10 |
Correct |
30 ms |
70768 KB |
Output is correct |
11 |
Correct |
35 ms |
70768 KB |
Output is correct |
12 |
Correct |
30 ms |
70712 KB |
Output is correct |
13 |
Correct |
30 ms |
70796 KB |
Output is correct |
14 |
Correct |
30 ms |
70740 KB |
Output is correct |
15 |
Correct |
30 ms |
70800 KB |
Output is correct |
16 |
Correct |
30 ms |
70744 KB |
Output is correct |
17 |
Correct |
30 ms |
70768 KB |
Output is correct |
18 |
Correct |
30 ms |
70748 KB |
Output is correct |
19 |
Correct |
30 ms |
70808 KB |
Output is correct |
20 |
Correct |
30 ms |
70672 KB |
Output is correct |
21 |
Correct |
31 ms |
70784 KB |
Output is correct |
22 |
Correct |
31 ms |
70684 KB |
Output is correct |
23 |
Correct |
30 ms |
70732 KB |
Output is correct |
24 |
Correct |
29 ms |
70680 KB |
Output is correct |
25 |
Correct |
35 ms |
70732 KB |
Output is correct |
26 |
Correct |
30 ms |
70716 KB |
Output is correct |
27 |
Correct |
40 ms |
70704 KB |
Output is correct |
28 |
Correct |
31 ms |
70792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
70664 KB |
Output is correct |
2 |
Correct |
614 ms |
94352 KB |
Output is correct |
3 |
Correct |
387 ms |
95048 KB |
Output is correct |
4 |
Correct |
583 ms |
97680 KB |
Output is correct |
5 |
Correct |
542 ms |
94800 KB |
Output is correct |
6 |
Correct |
380 ms |
94312 KB |
Output is correct |
7 |
Correct |
370 ms |
95140 KB |
Output is correct |
8 |
Correct |
279 ms |
95412 KB |
Output is correct |
9 |
Correct |
705 ms |
99304 KB |
Output is correct |
10 |
Correct |
411 ms |
99380 KB |
Output is correct |
11 |
Correct |
581 ms |
94484 KB |
Output is correct |
12 |
Correct |
354 ms |
94972 KB |
Output is correct |
13 |
Correct |
236 ms |
95068 KB |
Output is correct |
14 |
Correct |
242 ms |
95544 KB |
Output is correct |
15 |
Correct |
240 ms |
94968 KB |
Output is correct |
16 |
Correct |
248 ms |
95436 KB |
Output is correct |
17 |
Correct |
261 ms |
95836 KB |
Output is correct |
18 |
Correct |
34 ms |
70720 KB |
Output is correct |
19 |
Correct |
35 ms |
70732 KB |
Output is correct |
20 |
Correct |
35 ms |
70792 KB |
Output is correct |
21 |
Correct |
34 ms |
70724 KB |
Output is correct |
22 |
Correct |
34 ms |
70696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
70664 KB |
Output is correct |
2 |
Correct |
614 ms |
94352 KB |
Output is correct |
3 |
Correct |
387 ms |
95048 KB |
Output is correct |
4 |
Correct |
583 ms |
97680 KB |
Output is correct |
5 |
Correct |
542 ms |
94800 KB |
Output is correct |
6 |
Correct |
380 ms |
94312 KB |
Output is correct |
7 |
Correct |
370 ms |
95140 KB |
Output is correct |
8 |
Correct |
279 ms |
95412 KB |
Output is correct |
9 |
Correct |
705 ms |
99304 KB |
Output is correct |
10 |
Correct |
411 ms |
99380 KB |
Output is correct |
11 |
Correct |
581 ms |
94484 KB |
Output is correct |
12 |
Correct |
354 ms |
94972 KB |
Output is correct |
13 |
Correct |
236 ms |
95068 KB |
Output is correct |
14 |
Correct |
242 ms |
95544 KB |
Output is correct |
15 |
Correct |
240 ms |
94968 KB |
Output is correct |
16 |
Correct |
248 ms |
95436 KB |
Output is correct |
17 |
Correct |
261 ms |
95836 KB |
Output is correct |
18 |
Correct |
34 ms |
70720 KB |
Output is correct |
19 |
Correct |
35 ms |
70732 KB |
Output is correct |
20 |
Correct |
35 ms |
70792 KB |
Output is correct |
21 |
Correct |
34 ms |
70724 KB |
Output is correct |
22 |
Correct |
34 ms |
70696 KB |
Output is correct |
23 |
Correct |
36 ms |
70732 KB |
Output is correct |
24 |
Correct |
574 ms |
94672 KB |
Output is correct |
25 |
Correct |
395 ms |
95052 KB |
Output is correct |
26 |
Correct |
515 ms |
99512 KB |
Output is correct |
27 |
Correct |
465 ms |
94712 KB |
Output is correct |
28 |
Correct |
350 ms |
94920 KB |
Output is correct |
29 |
Correct |
325 ms |
94852 KB |
Output is correct |
30 |
Correct |
276 ms |
95376 KB |
Output is correct |
31 |
Correct |
602 ms |
97680 KB |
Output is correct |
32 |
Correct |
392 ms |
99536 KB |
Output is correct |
33 |
Correct |
577 ms |
94468 KB |
Output is correct |
34 |
Correct |
368 ms |
95160 KB |
Output is correct |
35 |
Correct |
33 ms |
70788 KB |
Output is correct |
36 |
Correct |
39 ms |
70728 KB |
Output is correct |
37 |
Correct |
34 ms |
70768 KB |
Output is correct |
38 |
Correct |
32 ms |
70692 KB |
Output is correct |
39 |
Correct |
30 ms |
70712 KB |
Output is correct |
40 |
Correct |
31 ms |
70712 KB |
Output is correct |
41 |
Correct |
32 ms |
70696 KB |
Output is correct |
42 |
Correct |
35 ms |
70680 KB |
Output is correct |
43 |
Correct |
36 ms |
70752 KB |
Output is correct |
44 |
Correct |
37 ms |
70676 KB |
Output is correct |
45 |
Correct |
33 ms |
70716 KB |
Output is correct |
46 |
Correct |
32 ms |
70712 KB |
Output is correct |
47 |
Correct |
32 ms |
70800 KB |
Output is correct |
48 |
Correct |
32 ms |
70708 KB |
Output is correct |
49 |
Correct |
32 ms |
70772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
70712 KB |
Output is correct |
2 |
Correct |
644 ms |
96448 KB |
Output is correct |
3 |
Correct |
767 ms |
95988 KB |
Output is correct |
4 |
Correct |
598 ms |
95600 KB |
Output is correct |
5 |
Correct |
554 ms |
91956 KB |
Output is correct |
6 |
Correct |
367 ms |
92012 KB |
Output is correct |
7 |
Correct |
336 ms |
92320 KB |
Output is correct |
8 |
Correct |
250 ms |
92364 KB |
Output is correct |
9 |
Correct |
645 ms |
94796 KB |
Output is correct |
10 |
Correct |
811 ms |
96468 KB |
Output is correct |
11 |
Correct |
566 ms |
91672 KB |
Output is correct |
12 |
Correct |
652 ms |
92368 KB |
Output is correct |
13 |
Correct |
413 ms |
93188 KB |
Output is correct |
14 |
Correct |
419 ms |
94052 KB |
Output is correct |
15 |
Correct |
32 ms |
70860 KB |
Output is correct |
16 |
Correct |
30 ms |
70784 KB |
Output is correct |
17 |
Correct |
30 ms |
70808 KB |
Output is correct |
18 |
Correct |
30 ms |
70684 KB |
Output is correct |
19 |
Correct |
30 ms |
70748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
70732 KB |
Output is correct |
2 |
Correct |
637 ms |
97160 KB |
Output is correct |
3 |
Correct |
775 ms |
94812 KB |
Output is correct |
4 |
Correct |
587 ms |
95920 KB |
Output is correct |
5 |
Correct |
548 ms |
93576 KB |
Output is correct |
6 |
Correct |
381 ms |
93492 KB |
Output is correct |
7 |
Correct |
361 ms |
93384 KB |
Output is correct |
8 |
Correct |
264 ms |
93352 KB |
Output is correct |
9 |
Correct |
682 ms |
98664 KB |
Output is correct |
10 |
Correct |
796 ms |
97384 KB |
Output is correct |
11 |
Correct |
604 ms |
94176 KB |
Output is correct |
12 |
Correct |
647 ms |
92876 KB |
Output is correct |
13 |
Correct |
429 ms |
93376 KB |
Output is correct |
14 |
Correct |
473 ms |
94216 KB |
Output is correct |
15 |
Correct |
34 ms |
70716 KB |
Output is correct |
16 |
Correct |
34 ms |
70792 KB |
Output is correct |
17 |
Correct |
34 ms |
70732 KB |
Output is correct |
18 |
Correct |
34 ms |
70704 KB |
Output is correct |
19 |
Correct |
34 ms |
70812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
70712 KB |
Output is correct |
2 |
Correct |
30 ms |
70676 KB |
Output is correct |
3 |
Correct |
30 ms |
70748 KB |
Output is correct |
4 |
Correct |
30 ms |
70860 KB |
Output is correct |
5 |
Correct |
31 ms |
70868 KB |
Output is correct |
6 |
Correct |
36 ms |
70828 KB |
Output is correct |
7 |
Correct |
30 ms |
70868 KB |
Output is correct |
8 |
Correct |
31 ms |
70816 KB |
Output is correct |
9 |
Correct |
31 ms |
70732 KB |
Output is correct |
10 |
Correct |
30 ms |
70768 KB |
Output is correct |
11 |
Correct |
35 ms |
70768 KB |
Output is correct |
12 |
Correct |
30 ms |
70712 KB |
Output is correct |
13 |
Correct |
30 ms |
70796 KB |
Output is correct |
14 |
Correct |
30 ms |
70740 KB |
Output is correct |
15 |
Correct |
30 ms |
70800 KB |
Output is correct |
16 |
Correct |
30 ms |
70744 KB |
Output is correct |
17 |
Correct |
30 ms |
70768 KB |
Output is correct |
18 |
Correct |
30 ms |
70748 KB |
Output is correct |
19 |
Correct |
30 ms |
70808 KB |
Output is correct |
20 |
Correct |
30 ms |
70672 KB |
Output is correct |
21 |
Correct |
31 ms |
70784 KB |
Output is correct |
22 |
Correct |
31 ms |
70684 KB |
Output is correct |
23 |
Correct |
30 ms |
70732 KB |
Output is correct |
24 |
Correct |
29 ms |
70680 KB |
Output is correct |
25 |
Correct |
35 ms |
70732 KB |
Output is correct |
26 |
Correct |
30 ms |
70716 KB |
Output is correct |
27 |
Correct |
40 ms |
70704 KB |
Output is correct |
28 |
Correct |
31 ms |
70792 KB |
Output is correct |
29 |
Correct |
30 ms |
70664 KB |
Output is correct |
30 |
Correct |
614 ms |
94352 KB |
Output is correct |
31 |
Correct |
387 ms |
95048 KB |
Output is correct |
32 |
Correct |
583 ms |
97680 KB |
Output is correct |
33 |
Correct |
542 ms |
94800 KB |
Output is correct |
34 |
Correct |
380 ms |
94312 KB |
Output is correct |
35 |
Correct |
370 ms |
95140 KB |
Output is correct |
36 |
Correct |
279 ms |
95412 KB |
Output is correct |
37 |
Correct |
705 ms |
99304 KB |
Output is correct |
38 |
Correct |
411 ms |
99380 KB |
Output is correct |
39 |
Correct |
581 ms |
94484 KB |
Output is correct |
40 |
Correct |
354 ms |
94972 KB |
Output is correct |
41 |
Correct |
236 ms |
95068 KB |
Output is correct |
42 |
Correct |
242 ms |
95544 KB |
Output is correct |
43 |
Correct |
240 ms |
94968 KB |
Output is correct |
44 |
Correct |
248 ms |
95436 KB |
Output is correct |
45 |
Correct |
261 ms |
95836 KB |
Output is correct |
46 |
Correct |
34 ms |
70720 KB |
Output is correct |
47 |
Correct |
35 ms |
70732 KB |
Output is correct |
48 |
Correct |
35 ms |
70792 KB |
Output is correct |
49 |
Correct |
34 ms |
70724 KB |
Output is correct |
50 |
Correct |
34 ms |
70696 KB |
Output is correct |
51 |
Correct |
36 ms |
70732 KB |
Output is correct |
52 |
Correct |
574 ms |
94672 KB |
Output is correct |
53 |
Correct |
395 ms |
95052 KB |
Output is correct |
54 |
Correct |
515 ms |
99512 KB |
Output is correct |
55 |
Correct |
465 ms |
94712 KB |
Output is correct |
56 |
Correct |
350 ms |
94920 KB |
Output is correct |
57 |
Correct |
325 ms |
94852 KB |
Output is correct |
58 |
Correct |
276 ms |
95376 KB |
Output is correct |
59 |
Correct |
602 ms |
97680 KB |
Output is correct |
60 |
Correct |
392 ms |
99536 KB |
Output is correct |
61 |
Correct |
577 ms |
94468 KB |
Output is correct |
62 |
Correct |
368 ms |
95160 KB |
Output is correct |
63 |
Correct |
33 ms |
70788 KB |
Output is correct |
64 |
Correct |
39 ms |
70728 KB |
Output is correct |
65 |
Correct |
34 ms |
70768 KB |
Output is correct |
66 |
Correct |
32 ms |
70692 KB |
Output is correct |
67 |
Correct |
30 ms |
70712 KB |
Output is correct |
68 |
Correct |
31 ms |
70712 KB |
Output is correct |
69 |
Correct |
32 ms |
70696 KB |
Output is correct |
70 |
Correct |
35 ms |
70680 KB |
Output is correct |
71 |
Correct |
36 ms |
70752 KB |
Output is correct |
72 |
Correct |
37 ms |
70676 KB |
Output is correct |
73 |
Correct |
33 ms |
70716 KB |
Output is correct |
74 |
Correct |
32 ms |
70712 KB |
Output is correct |
75 |
Correct |
32 ms |
70800 KB |
Output is correct |
76 |
Correct |
32 ms |
70708 KB |
Output is correct |
77 |
Correct |
32 ms |
70772 KB |
Output is correct |
78 |
Correct |
32 ms |
70712 KB |
Output is correct |
79 |
Correct |
644 ms |
96448 KB |
Output is correct |
80 |
Correct |
767 ms |
95988 KB |
Output is correct |
81 |
Correct |
598 ms |
95600 KB |
Output is correct |
82 |
Correct |
554 ms |
91956 KB |
Output is correct |
83 |
Correct |
367 ms |
92012 KB |
Output is correct |
84 |
Correct |
336 ms |
92320 KB |
Output is correct |
85 |
Correct |
250 ms |
92364 KB |
Output is correct |
86 |
Correct |
645 ms |
94796 KB |
Output is correct |
87 |
Correct |
811 ms |
96468 KB |
Output is correct |
88 |
Correct |
566 ms |
91672 KB |
Output is correct |
89 |
Correct |
652 ms |
92368 KB |
Output is correct |
90 |
Correct |
413 ms |
93188 KB |
Output is correct |
91 |
Correct |
419 ms |
94052 KB |
Output is correct |
92 |
Correct |
32 ms |
70860 KB |
Output is correct |
93 |
Correct |
30 ms |
70784 KB |
Output is correct |
94 |
Correct |
30 ms |
70808 KB |
Output is correct |
95 |
Correct |
30 ms |
70684 KB |
Output is correct |
96 |
Correct |
30 ms |
70748 KB |
Output is correct |
97 |
Correct |
29 ms |
70732 KB |
Output is correct |
98 |
Correct |
637 ms |
97160 KB |
Output is correct |
99 |
Correct |
775 ms |
94812 KB |
Output is correct |
100 |
Correct |
587 ms |
95920 KB |
Output is correct |
101 |
Correct |
548 ms |
93576 KB |
Output is correct |
102 |
Correct |
381 ms |
93492 KB |
Output is correct |
103 |
Correct |
361 ms |
93384 KB |
Output is correct |
104 |
Correct |
264 ms |
93352 KB |
Output is correct |
105 |
Correct |
682 ms |
98664 KB |
Output is correct |
106 |
Correct |
796 ms |
97384 KB |
Output is correct |
107 |
Correct |
604 ms |
94176 KB |
Output is correct |
108 |
Correct |
647 ms |
92876 KB |
Output is correct |
109 |
Correct |
429 ms |
93376 KB |
Output is correct |
110 |
Correct |
473 ms |
94216 KB |
Output is correct |
111 |
Correct |
34 ms |
70716 KB |
Output is correct |
112 |
Correct |
34 ms |
70792 KB |
Output is correct |
113 |
Correct |
34 ms |
70732 KB |
Output is correct |
114 |
Correct |
34 ms |
70704 KB |
Output is correct |
115 |
Correct |
34 ms |
70812 KB |
Output is correct |
116 |
Correct |
604 ms |
92604 KB |
Output is correct |
117 |
Correct |
718 ms |
95248 KB |
Output is correct |
118 |
Correct |
642 ms |
99456 KB |
Output is correct |
119 |
Correct |
583 ms |
94796 KB |
Output is correct |
120 |
Correct |
410 ms |
94408 KB |
Output is correct |
121 |
Correct |
406 ms |
95392 KB |
Output is correct |
122 |
Correct |
287 ms |
95388 KB |
Output is correct |
123 |
Correct |
720 ms |
98304 KB |
Output is correct |
124 |
Correct |
861 ms |
97648 KB |
Output is correct |
125 |
Correct |
639 ms |
93736 KB |
Output is correct |
126 |
Correct |
754 ms |
95008 KB |
Output is correct |
127 |
Correct |
718 ms |
95564 KB |
Output is correct |
128 |
Correct |
536 ms |
96332 KB |
Output is correct |
129 |
Correct |
543 ms |
96972 KB |
Output is correct |