# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
589582 | GioChkhaidze | Sprinkler (JOI22_sprinkler) | C++14 | 789 ms | 103276 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int N = 2e5 + 55;
const int K = 44;
int n, q, pr[N];
ll D[N][K], h[N], L;
vector < int > v[N];
void dfs(int x, int p) {
pr[x] = p;
for (int i = 0; i < v[x].size(); ++i) {
int to = v[x][i];
if (to == p) continue;
dfs(to, x);
}
}
main () {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> L;
for (int i = 1; i < n; ++i) {
int a, b;
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
dfs(1, 0);
int st = 0;
for (int i = n + 1; i <= n + 40; ++i) {
pr[st] = i;
st = i;
}
for (int i = 0; i <= n + 40; ++i) {
for (int j = 0; j <= 40; ++j) {
D[i][j] = 1;
}
}
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
cin >> q;
for (int i = 1; i <= q; ++i) {
int tp, x;
cin >> tp;
if (tp == 1) {
ll d, W;
cin >> x >> d >> W;
for (int j = d; j >= 0; --j) {
D[x][j] = (D[x][j] * W) % L;
if (0 < j) {
D[x][j - 1] = (D[x][j - 1] * W) % L;
}
D[x][j] %= L;
x = pr[x];
}
}
else
if (tp == 2) {
cin >> x;
ll ans = h[x];
for (int j = 0; j <= 40; ++j) {
ans = (ans * D[x][j]) % L;
x = pr[x];
}
cout << ans << "\n";
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |