#include<iostream>
#include<vector>
using namespace std;
using ll = long long;
const int N = 5e5 + 123;
const int LOG = 20;
const int D = 45;
ll h[N], q[N][D];
int n, L;
void mult(ll &a, ll b) {
a *= b;
a %= L;
}
vector<int>g[N];
int pr[N];
void dfs(int v) {
for (int to : g[v]) if (to != pr[v]) {
pr[to] = v;
dfs(to);
}
}
ll binpow(ll a, ll b) {
ll r = 1;
while (b) {
if (b & 1) r = r * a % L;
a = a * a % L;
b >>= 1;
}
return r;
}
ll ih[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> L;
for (int i = 1 ; i < n ; ++ i) {
int a, b;
cin >> a >> b;
g[a].emplace_back(b);
g[b].emplace_back(a);
}
int m = n;
g[1].emplace_back(++m);
g[m].emplace_back(1);
for (int i = 0 ; i < 44 ; ++ i) {
int x = m, y = m + 1;
++m;
g[x].emplace_back(y);
g[y].emplace_back(x);
}
dfs(m);
for (int i = 1 ; i <= m ; ++ i) {
for (int j = 0 ; j <= 40 ; ++ j) {
q[i][j] = 1;
}
}
for (int i = 1 ; i <= n ; ++ i) {
cin >> ih[i];
}
int qq;
cin >> qq;
while (qq--) {
int t, x, d, w;
cin >> t;
if (t == 1) {
cin >> x >> d >> w;
for (int i = d ; i >= 0 ; -- i) {
mult(q[x][i], w);
// cout << x << " upd\n";
x = pr[x];
}
} else {
cin >> x;
ll ans = ih[x];
for (int i = 0 ; i <= 10 ; ++ i) {
mult(ans, q[x][i]);
mult(ans, q[x][i+1]);
// cout << x << " get\n";
x = pr[x];
}
cout << ans << "\n";
//cout << ret*binpow(2, ans) % L << "\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
12088 KB |
Output is correct |
3 |
Correct |
7 ms |
11988 KB |
Output is correct |
4 |
Incorrect |
7 ms |
12500 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12108 KB |
Output is correct |
2 |
Correct |
357 ms |
94804 KB |
Output is correct |
3 |
Correct |
366 ms |
91600 KB |
Output is correct |
4 |
Correct |
393 ms |
97104 KB |
Output is correct |
5 |
Correct |
338 ms |
93132 KB |
Output is correct |
6 |
Correct |
328 ms |
93268 KB |
Output is correct |
7 |
Correct |
332 ms |
93448 KB |
Output is correct |
8 |
Correct |
282 ms |
93960 KB |
Output is correct |
9 |
Correct |
416 ms |
100588 KB |
Output is correct |
10 |
Correct |
361 ms |
97144 KB |
Output is correct |
11 |
Correct |
344 ms |
94796 KB |
Output is correct |
12 |
Correct |
340 ms |
91800 KB |
Output is correct |
13 |
Correct |
260 ms |
92220 KB |
Output is correct |
14 |
Correct |
241 ms |
92348 KB |
Output is correct |
15 |
Correct |
232 ms |
92256 KB |
Output is correct |
16 |
Correct |
270 ms |
92128 KB |
Output is correct |
17 |
Correct |
250 ms |
92836 KB |
Output is correct |
18 |
Correct |
6 ms |
12116 KB |
Output is correct |
19 |
Correct |
7 ms |
12116 KB |
Output is correct |
20 |
Correct |
8 ms |
12060 KB |
Output is correct |
21 |
Correct |
8 ms |
12032 KB |
Output is correct |
22 |
Correct |
9 ms |
12116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12108 KB |
Output is correct |
2 |
Correct |
357 ms |
94804 KB |
Output is correct |
3 |
Correct |
366 ms |
91600 KB |
Output is correct |
4 |
Correct |
393 ms |
97104 KB |
Output is correct |
5 |
Correct |
338 ms |
93132 KB |
Output is correct |
6 |
Correct |
328 ms |
93268 KB |
Output is correct |
7 |
Correct |
332 ms |
93448 KB |
Output is correct |
8 |
Correct |
282 ms |
93960 KB |
Output is correct |
9 |
Correct |
416 ms |
100588 KB |
Output is correct |
10 |
Correct |
361 ms |
97144 KB |
Output is correct |
11 |
Correct |
344 ms |
94796 KB |
Output is correct |
12 |
Correct |
340 ms |
91800 KB |
Output is correct |
13 |
Correct |
260 ms |
92220 KB |
Output is correct |
14 |
Correct |
241 ms |
92348 KB |
Output is correct |
15 |
Correct |
232 ms |
92256 KB |
Output is correct |
16 |
Correct |
270 ms |
92128 KB |
Output is correct |
17 |
Correct |
250 ms |
92836 KB |
Output is correct |
18 |
Correct |
6 ms |
12116 KB |
Output is correct |
19 |
Correct |
7 ms |
12116 KB |
Output is correct |
20 |
Correct |
8 ms |
12060 KB |
Output is correct |
21 |
Correct |
8 ms |
12032 KB |
Output is correct |
22 |
Correct |
9 ms |
12116 KB |
Output is correct |
23 |
Correct |
7 ms |
12008 KB |
Output is correct |
24 |
Correct |
370 ms |
94704 KB |
Output is correct |
25 |
Correct |
352 ms |
92364 KB |
Output is correct |
26 |
Correct |
362 ms |
99592 KB |
Output is correct |
27 |
Correct |
422 ms |
93884 KB |
Output is correct |
28 |
Correct |
326 ms |
93996 KB |
Output is correct |
29 |
Correct |
350 ms |
94020 KB |
Output is correct |
30 |
Correct |
280 ms |
94688 KB |
Output is correct |
31 |
Correct |
444 ms |
99676 KB |
Output is correct |
32 |
Correct |
334 ms |
97796 KB |
Output is correct |
33 |
Correct |
385 ms |
95516 KB |
Output is correct |
34 |
Correct |
361 ms |
92348 KB |
Output is correct |
35 |
Correct |
6 ms |
12096 KB |
Output is correct |
36 |
Correct |
7 ms |
12096 KB |
Output is correct |
37 |
Correct |
8 ms |
12116 KB |
Output is correct |
38 |
Correct |
6 ms |
12116 KB |
Output is correct |
39 |
Correct |
6 ms |
12116 KB |
Output is correct |
40 |
Correct |
7 ms |
12116 KB |
Output is correct |
41 |
Correct |
7 ms |
12116 KB |
Output is correct |
42 |
Correct |
7 ms |
12084 KB |
Output is correct |
43 |
Correct |
9 ms |
11996 KB |
Output is correct |
44 |
Correct |
7 ms |
12116 KB |
Output is correct |
45 |
Correct |
7 ms |
12136 KB |
Output is correct |
46 |
Correct |
6 ms |
12096 KB |
Output is correct |
47 |
Correct |
7 ms |
12004 KB |
Output is correct |
48 |
Correct |
7 ms |
12116 KB |
Output is correct |
49 |
Correct |
7 ms |
12096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Incorrect |
412 ms |
98504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Incorrect |
430 ms |
98692 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
12088 KB |
Output is correct |
3 |
Correct |
7 ms |
11988 KB |
Output is correct |
4 |
Incorrect |
7 ms |
12500 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |