#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 25;
vector <int> adj[MAXN];
int p[MAXN], h[MAXN], n, l, q;
int lazy[MAXN];
void fix (int pos, int par) {
p[pos] = par;
for (int j = 0; j < (int)adj[pos].size(); j++) {
if (adj[pos][j] == par) {
adj[pos].erase(adj[pos].begin() + j);
break;
}
}
for (auto j : adj[pos]) {
fix(j, pos);
}
}
int main () {
cin >> n >> l;
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i = 1; i <= n; i++) cin >> h[i];
for (int i = 1; i <= n; i++) lazy[i] = 1;
fix(1, -1);
cin >> q;
while (q--) {
int t;
cin >> t;
if (t == 1) {
int x, d, w;
cin >> x >> d >> w;
if (d == 0) {
h[x] = (h[x] * 1ll * w) % l;
} else if (d == 1) {
if (p[x] != -1) {
h[p[x]] = (h[p[x]] * 1ll * w) % l;
lazy[x] = (lazy[x] * 1ll * w) % l;
} else {
lazy[x] = (lazy[x] * 1ll * w) % l;
}
}
} else {
int x;
cin >> x;
int z = h[x];
z = (z * 1ll * lazy[x]) % l;
if (p[x] != -1) z = (z * 1ll * lazy[p[x]]) % l;
cout << z << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
7260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7260 KB |
Output is correct |
2 |
Correct |
809 ms |
21588 KB |
Output is correct |
3 |
Correct |
554 ms |
20332 KB |
Output is correct |
4 |
Correct |
679 ms |
26832 KB |
Output is correct |
5 |
Correct |
675 ms |
21052 KB |
Output is correct |
6 |
Correct |
675 ms |
20892 KB |
Output is correct |
7 |
Correct |
668 ms |
21596 KB |
Output is correct |
8 |
Correct |
644 ms |
21620 KB |
Output is correct |
9 |
Correct |
793 ms |
30508 KB |
Output is correct |
10 |
Correct |
550 ms |
28480 KB |
Output is correct |
11 |
Correct |
797 ms |
21628 KB |
Output is correct |
12 |
Correct |
552 ms |
20248 KB |
Output is correct |
13 |
Correct |
515 ms |
24464 KB |
Output is correct |
14 |
Correct |
522 ms |
26808 KB |
Output is correct |
15 |
Correct |
505 ms |
26192 KB |
Output is correct |
16 |
Correct |
520 ms |
26704 KB |
Output is correct |
17 |
Correct |
518 ms |
27216 KB |
Output is correct |
18 |
Correct |
3 ms |
7260 KB |
Output is correct |
19 |
Correct |
2 ms |
7260 KB |
Output is correct |
20 |
Correct |
2 ms |
7260 KB |
Output is correct |
21 |
Correct |
3 ms |
7084 KB |
Output is correct |
22 |
Correct |
3 ms |
7260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7260 KB |
Output is correct |
2 |
Correct |
809 ms |
21588 KB |
Output is correct |
3 |
Correct |
554 ms |
20332 KB |
Output is correct |
4 |
Correct |
679 ms |
26832 KB |
Output is correct |
5 |
Correct |
675 ms |
21052 KB |
Output is correct |
6 |
Correct |
675 ms |
20892 KB |
Output is correct |
7 |
Correct |
668 ms |
21596 KB |
Output is correct |
8 |
Correct |
644 ms |
21620 KB |
Output is correct |
9 |
Correct |
793 ms |
30508 KB |
Output is correct |
10 |
Correct |
550 ms |
28480 KB |
Output is correct |
11 |
Correct |
797 ms |
21628 KB |
Output is correct |
12 |
Correct |
552 ms |
20248 KB |
Output is correct |
13 |
Correct |
515 ms |
24464 KB |
Output is correct |
14 |
Correct |
522 ms |
26808 KB |
Output is correct |
15 |
Correct |
505 ms |
26192 KB |
Output is correct |
16 |
Correct |
520 ms |
26704 KB |
Output is correct |
17 |
Correct |
518 ms |
27216 KB |
Output is correct |
18 |
Correct |
3 ms |
7260 KB |
Output is correct |
19 |
Correct |
2 ms |
7260 KB |
Output is correct |
20 |
Correct |
2 ms |
7260 KB |
Output is correct |
21 |
Correct |
3 ms |
7084 KB |
Output is correct |
22 |
Correct |
3 ms |
7260 KB |
Output is correct |
23 |
Incorrect |
2 ms |
7260 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
7256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
7260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |