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>
using namespace std;
int n, l, s, t;
vector<int> edg[200045];
long long h[200045];
int q;
int op, x, d, k;
int anc[200045];
long long v[200045][41];
void dfs(int x, int p) {
anc[x] = p;
for(int i:edg[x]) {
if(i!=p) {
dfs(i, x);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> l;
for(int i=0; i<n-1; i++) {
cin >> s >> t;
edg[s].push_back(t);
edg[t].push_back(s);
}
for(int i=1; i<=n; i++) {
cin >> h[i];
}
for(int i=n+1; i<n+40; i++) {
edg[i].push_back(i+1);
}
edg[n+40].push_back(1);
dfs(n+1, -1);
cin >> q;
for(int i=1; i<=n+40; i++) {
for(int j=0; j<=40; j++) {
v[i][j] = 1;
}
}
while(q--) {
cin >> op >> x;
if(op==1) {
cin >> d >> k;
int ptr = x;
for(int i=0; i<=d; i++) {
v[ptr][d-i] = (v[ptr][d-i] * k) % l;
if(i<d) v[ptr][d-1-i] = (v[ptr][d-1-i] * k) % l;
ptr = anc[ptr];
}
} else {
int ptr = x;
long long ans = h[x];
for(int i=0; i<=40; i++) {
ans = (ans * v[ptr][i]) % l;
ptr = anc[ptr];
}
cout << ans << "\n";
}
}
}
# | 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... |