#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 <= 43 ; ++ 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 <= 39 ; ++ 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";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
8 ms |
12016 KB |
Output is correct |
3 |
Correct |
7 ms |
12008 KB |
Output is correct |
4 |
Incorrect |
8 ms |
12500 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
507 ms |
94912 KB |
Output is correct |
3 |
Correct |
323 ms |
91756 KB |
Output is correct |
4 |
Correct |
450 ms |
97128 KB |
Output is correct |
5 |
Correct |
414 ms |
93188 KB |
Output is correct |
6 |
Correct |
386 ms |
93180 KB |
Output is correct |
7 |
Correct |
357 ms |
93480 KB |
Output is correct |
8 |
Correct |
334 ms |
93868 KB |
Output is correct |
9 |
Correct |
593 ms |
100700 KB |
Output is correct |
10 |
Correct |
351 ms |
97108 KB |
Output is correct |
11 |
Correct |
523 ms |
94800 KB |
Output is correct |
12 |
Correct |
328 ms |
91648 KB |
Output is correct |
13 |
Correct |
288 ms |
92284 KB |
Output is correct |
14 |
Correct |
240 ms |
92152 KB |
Output is correct |
15 |
Correct |
232 ms |
92260 KB |
Output is correct |
16 |
Correct |
243 ms |
92076 KB |
Output is correct |
17 |
Correct |
244 ms |
92656 KB |
Output is correct |
18 |
Correct |
6 ms |
12116 KB |
Output is correct |
19 |
Correct |
6 ms |
12048 KB |
Output is correct |
20 |
Correct |
7 ms |
12116 KB |
Output is correct |
21 |
Correct |
6 ms |
12116 KB |
Output is correct |
22 |
Correct |
6 ms |
12116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
507 ms |
94912 KB |
Output is correct |
3 |
Correct |
323 ms |
91756 KB |
Output is correct |
4 |
Correct |
450 ms |
97128 KB |
Output is correct |
5 |
Correct |
414 ms |
93188 KB |
Output is correct |
6 |
Correct |
386 ms |
93180 KB |
Output is correct |
7 |
Correct |
357 ms |
93480 KB |
Output is correct |
8 |
Correct |
334 ms |
93868 KB |
Output is correct |
9 |
Correct |
593 ms |
100700 KB |
Output is correct |
10 |
Correct |
351 ms |
97108 KB |
Output is correct |
11 |
Correct |
523 ms |
94800 KB |
Output is correct |
12 |
Correct |
328 ms |
91648 KB |
Output is correct |
13 |
Correct |
288 ms |
92284 KB |
Output is correct |
14 |
Correct |
240 ms |
92152 KB |
Output is correct |
15 |
Correct |
232 ms |
92260 KB |
Output is correct |
16 |
Correct |
243 ms |
92076 KB |
Output is correct |
17 |
Correct |
244 ms |
92656 KB |
Output is correct |
18 |
Correct |
6 ms |
12116 KB |
Output is correct |
19 |
Correct |
6 ms |
12048 KB |
Output is correct |
20 |
Correct |
7 ms |
12116 KB |
Output is correct |
21 |
Correct |
6 ms |
12116 KB |
Output is correct |
22 |
Correct |
6 ms |
12116 KB |
Output is correct |
23 |
Correct |
6 ms |
11988 KB |
Output is correct |
24 |
Correct |
542 ms |
94912 KB |
Output is correct |
25 |
Correct |
343 ms |
91580 KB |
Output is correct |
26 |
Correct |
458 ms |
98872 KB |
Output is correct |
27 |
Correct |
456 ms |
93156 KB |
Output is correct |
28 |
Correct |
371 ms |
93388 KB |
Output is correct |
29 |
Correct |
378 ms |
93316 KB |
Output is correct |
30 |
Correct |
324 ms |
93952 KB |
Output is correct |
31 |
Correct |
584 ms |
98892 KB |
Output is correct |
32 |
Correct |
355 ms |
97220 KB |
Output is correct |
33 |
Correct |
486 ms |
94732 KB |
Output is correct |
34 |
Correct |
334 ms |
91516 KB |
Output is correct |
35 |
Correct |
7 ms |
12116 KB |
Output is correct |
36 |
Correct |
6 ms |
12116 KB |
Output is correct |
37 |
Correct |
6 ms |
12116 KB |
Output is correct |
38 |
Correct |
6 ms |
12060 KB |
Output is correct |
39 |
Correct |
6 ms |
12116 KB |
Output is correct |
40 |
Correct |
6 ms |
11988 KB |
Output is correct |
41 |
Correct |
6 ms |
12068 KB |
Output is correct |
42 |
Correct |
6 ms |
11988 KB |
Output is correct |
43 |
Correct |
8 ms |
11988 KB |
Output is correct |
44 |
Correct |
6 ms |
12116 KB |
Output is correct |
45 |
Correct |
7 ms |
12116 KB |
Output is correct |
46 |
Correct |
6 ms |
12116 KB |
Output is correct |
47 |
Correct |
6 ms |
12120 KB |
Output is correct |
48 |
Correct |
7 ms |
12008 KB |
Output is correct |
49 |
Correct |
6 ms |
12116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Incorrect |
632 ms |
97940 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Incorrect |
621 ms |
98660 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
8 ms |
12016 KB |
Output is correct |
3 |
Correct |
7 ms |
12008 KB |
Output is correct |
4 |
Incorrect |
8 ms |
12500 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |