#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 200'010, D = 42;
vector<int> A[N];
int par[N];
ll op[N][D];
ll ini[N];
int n, l;
void dfs(int v, int p)
{
par[v] = p;
for (int u : A[v]) {
if (u != p)
dfs(u, v);
}
}
void do_op(int v, int d, int w)
{
if (par[v] == -1) {
Loop (i,0,d+1)
op[v][i] = op[v][i] * w % l;
return;
}
if (d == 0) {
op[v][0] = op[v][0] * w % l;
return;
}
op[v][d] = op[v][d] * w % l;
op[v][d-1] = op[v][d-1] * w % l;
do_op(par[v], d-1, w);
}
ll get(int v)
{
int d = 0;
ll x = ini[v] % l;
while (v != -1 && d < D) {
x = x * op[v][d] % l;
v = par[v];
d++;
}
return x;
}
int main()
{
Loop (i,0,N) Loop (j,0,D)
op[i][j] = 1;
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> l;
Loop (i,1,n) {
int v, u;
cin >> v >> u;
--v; --u;
A[v].push_back(u);
A[u].push_back(v);
}
dfs(0, -1);
Loop (i,0,n)
cin >> ini[i];
int q;
cin >> q;
while (q--) {
int t;
cin >> t;
if (t == 1) {
int x, d, w;
cin >> x >> d >> w;
do_op(x-1, d, w);
} else {
int x;
cin >> x;
cout << get(x-1) << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
73048 KB |
Output is correct |
2 |
Correct |
8 ms |
73052 KB |
Output is correct |
3 |
Correct |
8 ms |
73052 KB |
Output is correct |
4 |
Correct |
9 ms |
73052 KB |
Output is correct |
5 |
Correct |
9 ms |
73052 KB |
Output is correct |
6 |
Correct |
9 ms |
73052 KB |
Output is correct |
7 |
Correct |
9 ms |
73052 KB |
Output is correct |
8 |
Correct |
9 ms |
73052 KB |
Output is correct |
9 |
Correct |
8 ms |
73052 KB |
Output is correct |
10 |
Correct |
9 ms |
73048 KB |
Output is correct |
11 |
Correct |
10 ms |
73048 KB |
Output is correct |
12 |
Correct |
12 ms |
73052 KB |
Output is correct |
13 |
Correct |
8 ms |
73052 KB |
Output is correct |
14 |
Correct |
9 ms |
73052 KB |
Output is correct |
15 |
Correct |
8 ms |
73012 KB |
Output is correct |
16 |
Correct |
9 ms |
73052 KB |
Output is correct |
17 |
Correct |
9 ms |
73008 KB |
Output is correct |
18 |
Correct |
9 ms |
73052 KB |
Output is correct |
19 |
Correct |
8 ms |
73052 KB |
Output is correct |
20 |
Correct |
8 ms |
73052 KB |
Output is correct |
21 |
Correct |
8 ms |
72956 KB |
Output is correct |
22 |
Correct |
9 ms |
73052 KB |
Output is correct |
23 |
Correct |
8 ms |
73008 KB |
Output is correct |
24 |
Correct |
8 ms |
73052 KB |
Output is correct |
25 |
Correct |
9 ms |
72992 KB |
Output is correct |
26 |
Correct |
8 ms |
72940 KB |
Output is correct |
27 |
Correct |
12 ms |
73036 KB |
Output is correct |
28 |
Correct |
9 ms |
73052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
73052 KB |
Output is correct |
2 |
Correct |
279 ms |
83136 KB |
Output is correct |
3 |
Correct |
186 ms |
79956 KB |
Output is correct |
4 |
Correct |
265 ms |
84308 KB |
Output is correct |
5 |
Correct |
218 ms |
81520 KB |
Output is correct |
6 |
Correct |
173 ms |
81712 KB |
Output is correct |
7 |
Correct |
160 ms |
81652 KB |
Output is correct |
8 |
Correct |
148 ms |
87492 KB |
Output is correct |
9 |
Correct |
342 ms |
95312 KB |
Output is correct |
10 |
Correct |
187 ms |
95568 KB |
Output is correct |
11 |
Correct |
292 ms |
91216 KB |
Output is correct |
12 |
Correct |
174 ms |
91908 KB |
Output is correct |
13 |
Correct |
127 ms |
92196 KB |
Output is correct |
14 |
Correct |
139 ms |
92484 KB |
Output is correct |
15 |
Correct |
127 ms |
91852 KB |
Output is correct |
16 |
Correct |
129 ms |
92500 KB |
Output is correct |
17 |
Correct |
130 ms |
93008 KB |
Output is correct |
18 |
Correct |
9 ms |
73084 KB |
Output is correct |
19 |
Correct |
10 ms |
73052 KB |
Output is correct |
20 |
Correct |
8 ms |
72968 KB |
Output is correct |
21 |
Correct |
8 ms |
73052 KB |
Output is correct |
22 |
Correct |
10 ms |
73052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
73052 KB |
Output is correct |
2 |
Correct |
279 ms |
83136 KB |
Output is correct |
3 |
Correct |
186 ms |
79956 KB |
Output is correct |
4 |
Correct |
265 ms |
84308 KB |
Output is correct |
5 |
Correct |
218 ms |
81520 KB |
Output is correct |
6 |
Correct |
173 ms |
81712 KB |
Output is correct |
7 |
Correct |
160 ms |
81652 KB |
Output is correct |
8 |
Correct |
148 ms |
87492 KB |
Output is correct |
9 |
Correct |
342 ms |
95312 KB |
Output is correct |
10 |
Correct |
187 ms |
95568 KB |
Output is correct |
11 |
Correct |
292 ms |
91216 KB |
Output is correct |
12 |
Correct |
174 ms |
91908 KB |
Output is correct |
13 |
Correct |
127 ms |
92196 KB |
Output is correct |
14 |
Correct |
139 ms |
92484 KB |
Output is correct |
15 |
Correct |
127 ms |
91852 KB |
Output is correct |
16 |
Correct |
129 ms |
92500 KB |
Output is correct |
17 |
Correct |
130 ms |
93008 KB |
Output is correct |
18 |
Correct |
9 ms |
73084 KB |
Output is correct |
19 |
Correct |
10 ms |
73052 KB |
Output is correct |
20 |
Correct |
8 ms |
72968 KB |
Output is correct |
21 |
Correct |
8 ms |
73052 KB |
Output is correct |
22 |
Correct |
10 ms |
73052 KB |
Output is correct |
23 |
Correct |
8 ms |
73048 KB |
Output is correct |
24 |
Correct |
280 ms |
91300 KB |
Output is correct |
25 |
Correct |
192 ms |
91700 KB |
Output is correct |
26 |
Correct |
262 ms |
95588 KB |
Output is correct |
27 |
Correct |
235 ms |
91476 KB |
Output is correct |
28 |
Correct |
168 ms |
91732 KB |
Output is correct |
29 |
Correct |
157 ms |
91408 KB |
Output is correct |
30 |
Correct |
150 ms |
92460 KB |
Output is correct |
31 |
Correct |
361 ms |
94292 KB |
Output is correct |
32 |
Correct |
183 ms |
95572 KB |
Output is correct |
33 |
Correct |
286 ms |
91220 KB |
Output is correct |
34 |
Correct |
178 ms |
91732 KB |
Output is correct |
35 |
Correct |
9 ms |
73048 KB |
Output is correct |
36 |
Correct |
9 ms |
73048 KB |
Output is correct |
37 |
Correct |
9 ms |
73096 KB |
Output is correct |
38 |
Correct |
10 ms |
73052 KB |
Output is correct |
39 |
Correct |
9 ms |
73052 KB |
Output is correct |
40 |
Correct |
9 ms |
73052 KB |
Output is correct |
41 |
Correct |
9 ms |
73052 KB |
Output is correct |
42 |
Correct |
9 ms |
73092 KB |
Output is correct |
43 |
Correct |
9 ms |
72992 KB |
Output is correct |
44 |
Correct |
8 ms |
73052 KB |
Output is correct |
45 |
Correct |
8 ms |
73096 KB |
Output is correct |
46 |
Correct |
9 ms |
73052 KB |
Output is correct |
47 |
Correct |
8 ms |
73052 KB |
Output is correct |
48 |
Correct |
9 ms |
72964 KB |
Output is correct |
49 |
Correct |
9 ms |
73052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
73048 KB |
Output is correct |
2 |
Correct |
352 ms |
84616 KB |
Output is correct |
3 |
Correct |
371 ms |
82760 KB |
Output is correct |
4 |
Correct |
313 ms |
83652 KB |
Output is correct |
5 |
Correct |
252 ms |
79956 KB |
Output is correct |
6 |
Correct |
176 ms |
79952 KB |
Output is correct |
7 |
Correct |
184 ms |
80208 KB |
Output is correct |
8 |
Correct |
139 ms |
84420 KB |
Output is correct |
9 |
Correct |
353 ms |
91220 KB |
Output is correct |
10 |
Correct |
402 ms |
92752 KB |
Output is correct |
11 |
Correct |
304 ms |
88144 KB |
Output is correct |
12 |
Correct |
296 ms |
89044 KB |
Output is correct |
13 |
Correct |
202 ms |
89964 KB |
Output is correct |
14 |
Correct |
203 ms |
90492 KB |
Output is correct |
15 |
Correct |
9 ms |
73048 KB |
Output is correct |
16 |
Correct |
10 ms |
73052 KB |
Output is correct |
17 |
Correct |
9 ms |
73052 KB |
Output is correct |
18 |
Correct |
9 ms |
73052 KB |
Output is correct |
19 |
Correct |
8 ms |
73052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
73052 KB |
Output is correct |
2 |
Correct |
355 ms |
86040 KB |
Output is correct |
3 |
Correct |
368 ms |
82016 KB |
Output is correct |
4 |
Correct |
313 ms |
83832 KB |
Output is correct |
5 |
Correct |
273 ms |
81392 KB |
Output is correct |
6 |
Correct |
189 ms |
81652 KB |
Output is correct |
7 |
Correct |
166 ms |
81488 KB |
Output is correct |
8 |
Correct |
154 ms |
85956 KB |
Output is correct |
9 |
Correct |
392 ms |
94804 KB |
Output is correct |
10 |
Correct |
385 ms |
93420 KB |
Output is correct |
11 |
Correct |
302 ms |
90792 KB |
Output is correct |
12 |
Correct |
301 ms |
89424 KB |
Output is correct |
13 |
Correct |
226 ms |
90052 KB |
Output is correct |
14 |
Correct |
204 ms |
90712 KB |
Output is correct |
15 |
Correct |
10 ms |
73052 KB |
Output is correct |
16 |
Correct |
9 ms |
73048 KB |
Output is correct |
17 |
Correct |
8 ms |
73052 KB |
Output is correct |
18 |
Correct |
11 ms |
72980 KB |
Output is correct |
19 |
Correct |
9 ms |
73052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
73048 KB |
Output is correct |
2 |
Correct |
8 ms |
73052 KB |
Output is correct |
3 |
Correct |
8 ms |
73052 KB |
Output is correct |
4 |
Correct |
9 ms |
73052 KB |
Output is correct |
5 |
Correct |
9 ms |
73052 KB |
Output is correct |
6 |
Correct |
9 ms |
73052 KB |
Output is correct |
7 |
Correct |
9 ms |
73052 KB |
Output is correct |
8 |
Correct |
9 ms |
73052 KB |
Output is correct |
9 |
Correct |
8 ms |
73052 KB |
Output is correct |
10 |
Correct |
9 ms |
73048 KB |
Output is correct |
11 |
Correct |
10 ms |
73048 KB |
Output is correct |
12 |
Correct |
12 ms |
73052 KB |
Output is correct |
13 |
Correct |
8 ms |
73052 KB |
Output is correct |
14 |
Correct |
9 ms |
73052 KB |
Output is correct |
15 |
Correct |
8 ms |
73012 KB |
Output is correct |
16 |
Correct |
9 ms |
73052 KB |
Output is correct |
17 |
Correct |
9 ms |
73008 KB |
Output is correct |
18 |
Correct |
9 ms |
73052 KB |
Output is correct |
19 |
Correct |
8 ms |
73052 KB |
Output is correct |
20 |
Correct |
8 ms |
73052 KB |
Output is correct |
21 |
Correct |
8 ms |
72956 KB |
Output is correct |
22 |
Correct |
9 ms |
73052 KB |
Output is correct |
23 |
Correct |
8 ms |
73008 KB |
Output is correct |
24 |
Correct |
8 ms |
73052 KB |
Output is correct |
25 |
Correct |
9 ms |
72992 KB |
Output is correct |
26 |
Correct |
8 ms |
72940 KB |
Output is correct |
27 |
Correct |
12 ms |
73036 KB |
Output is correct |
28 |
Correct |
9 ms |
73052 KB |
Output is correct |
29 |
Correct |
8 ms |
73052 KB |
Output is correct |
30 |
Correct |
279 ms |
83136 KB |
Output is correct |
31 |
Correct |
186 ms |
79956 KB |
Output is correct |
32 |
Correct |
265 ms |
84308 KB |
Output is correct |
33 |
Correct |
218 ms |
81520 KB |
Output is correct |
34 |
Correct |
173 ms |
81712 KB |
Output is correct |
35 |
Correct |
160 ms |
81652 KB |
Output is correct |
36 |
Correct |
148 ms |
87492 KB |
Output is correct |
37 |
Correct |
342 ms |
95312 KB |
Output is correct |
38 |
Correct |
187 ms |
95568 KB |
Output is correct |
39 |
Correct |
292 ms |
91216 KB |
Output is correct |
40 |
Correct |
174 ms |
91908 KB |
Output is correct |
41 |
Correct |
127 ms |
92196 KB |
Output is correct |
42 |
Correct |
139 ms |
92484 KB |
Output is correct |
43 |
Correct |
127 ms |
91852 KB |
Output is correct |
44 |
Correct |
129 ms |
92500 KB |
Output is correct |
45 |
Correct |
130 ms |
93008 KB |
Output is correct |
46 |
Correct |
9 ms |
73084 KB |
Output is correct |
47 |
Correct |
10 ms |
73052 KB |
Output is correct |
48 |
Correct |
8 ms |
72968 KB |
Output is correct |
49 |
Correct |
8 ms |
73052 KB |
Output is correct |
50 |
Correct |
10 ms |
73052 KB |
Output is correct |
51 |
Correct |
8 ms |
73048 KB |
Output is correct |
52 |
Correct |
280 ms |
91300 KB |
Output is correct |
53 |
Correct |
192 ms |
91700 KB |
Output is correct |
54 |
Correct |
262 ms |
95588 KB |
Output is correct |
55 |
Correct |
235 ms |
91476 KB |
Output is correct |
56 |
Correct |
168 ms |
91732 KB |
Output is correct |
57 |
Correct |
157 ms |
91408 KB |
Output is correct |
58 |
Correct |
150 ms |
92460 KB |
Output is correct |
59 |
Correct |
361 ms |
94292 KB |
Output is correct |
60 |
Correct |
183 ms |
95572 KB |
Output is correct |
61 |
Correct |
286 ms |
91220 KB |
Output is correct |
62 |
Correct |
178 ms |
91732 KB |
Output is correct |
63 |
Correct |
9 ms |
73048 KB |
Output is correct |
64 |
Correct |
9 ms |
73048 KB |
Output is correct |
65 |
Correct |
9 ms |
73096 KB |
Output is correct |
66 |
Correct |
10 ms |
73052 KB |
Output is correct |
67 |
Correct |
9 ms |
73052 KB |
Output is correct |
68 |
Correct |
9 ms |
73052 KB |
Output is correct |
69 |
Correct |
9 ms |
73052 KB |
Output is correct |
70 |
Correct |
9 ms |
73092 KB |
Output is correct |
71 |
Correct |
9 ms |
72992 KB |
Output is correct |
72 |
Correct |
8 ms |
73052 KB |
Output is correct |
73 |
Correct |
8 ms |
73096 KB |
Output is correct |
74 |
Correct |
9 ms |
73052 KB |
Output is correct |
75 |
Correct |
8 ms |
73052 KB |
Output is correct |
76 |
Correct |
9 ms |
72964 KB |
Output is correct |
77 |
Correct |
9 ms |
73052 KB |
Output is correct |
78 |
Correct |
9 ms |
73048 KB |
Output is correct |
79 |
Correct |
352 ms |
84616 KB |
Output is correct |
80 |
Correct |
371 ms |
82760 KB |
Output is correct |
81 |
Correct |
313 ms |
83652 KB |
Output is correct |
82 |
Correct |
252 ms |
79956 KB |
Output is correct |
83 |
Correct |
176 ms |
79952 KB |
Output is correct |
84 |
Correct |
184 ms |
80208 KB |
Output is correct |
85 |
Correct |
139 ms |
84420 KB |
Output is correct |
86 |
Correct |
353 ms |
91220 KB |
Output is correct |
87 |
Correct |
402 ms |
92752 KB |
Output is correct |
88 |
Correct |
304 ms |
88144 KB |
Output is correct |
89 |
Correct |
296 ms |
89044 KB |
Output is correct |
90 |
Correct |
202 ms |
89964 KB |
Output is correct |
91 |
Correct |
203 ms |
90492 KB |
Output is correct |
92 |
Correct |
9 ms |
73048 KB |
Output is correct |
93 |
Correct |
10 ms |
73052 KB |
Output is correct |
94 |
Correct |
9 ms |
73052 KB |
Output is correct |
95 |
Correct |
9 ms |
73052 KB |
Output is correct |
96 |
Correct |
8 ms |
73052 KB |
Output is correct |
97 |
Correct |
9 ms |
73052 KB |
Output is correct |
98 |
Correct |
355 ms |
86040 KB |
Output is correct |
99 |
Correct |
368 ms |
82016 KB |
Output is correct |
100 |
Correct |
313 ms |
83832 KB |
Output is correct |
101 |
Correct |
273 ms |
81392 KB |
Output is correct |
102 |
Correct |
189 ms |
81652 KB |
Output is correct |
103 |
Correct |
166 ms |
81488 KB |
Output is correct |
104 |
Correct |
154 ms |
85956 KB |
Output is correct |
105 |
Correct |
392 ms |
94804 KB |
Output is correct |
106 |
Correct |
385 ms |
93420 KB |
Output is correct |
107 |
Correct |
302 ms |
90792 KB |
Output is correct |
108 |
Correct |
301 ms |
89424 KB |
Output is correct |
109 |
Correct |
226 ms |
90052 KB |
Output is correct |
110 |
Correct |
204 ms |
90712 KB |
Output is correct |
111 |
Correct |
10 ms |
73052 KB |
Output is correct |
112 |
Correct |
9 ms |
73048 KB |
Output is correct |
113 |
Correct |
8 ms |
73052 KB |
Output is correct |
114 |
Correct |
11 ms |
72980 KB |
Output is correct |
115 |
Correct |
9 ms |
73052 KB |
Output is correct |
116 |
Correct |
307 ms |
89304 KB |
Output is correct |
117 |
Correct |
311 ms |
91728 KB |
Output is correct |
118 |
Correct |
328 ms |
95568 KB |
Output is correct |
119 |
Correct |
268 ms |
91476 KB |
Output is correct |
120 |
Correct |
182 ms |
91220 KB |
Output is correct |
121 |
Correct |
199 ms |
92092 KB |
Output is correct |
122 |
Correct |
147 ms |
92272 KB |
Output is correct |
123 |
Correct |
371 ms |
94592 KB |
Output is correct |
124 |
Correct |
397 ms |
94032 KB |
Output is correct |
125 |
Correct |
326 ms |
90452 KB |
Output is correct |
126 |
Correct |
314 ms |
91728 KB |
Output is correct |
127 |
Correct |
315 ms |
92240 KB |
Output is correct |
128 |
Correct |
231 ms |
92828 KB |
Output is correct |
129 |
Correct |
218 ms |
93396 KB |
Output is correct |