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;
vector <int> g[200050];
long long pa[200050],mut[200050][41];
void dfs(int cur,int prv){
for (int i=0; i<=40; i++) mut[cur][i]=1;
pa[cur]=prv;
for (int i:g[cur]){
if (i!=prv) dfs(i,cur);
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
long long n,l;
cin>>n>>l;
for (int i=1; i<n; i++){
int u,v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
g[n+1].push_back(1);
for (int i=n+2; i<=n+40; i++) g[i].push_back(i-1);
dfs(n+40,0);
long long h[n+1];
for (int i=1; i<=n; i++) cin>>h[i];
int q; cin>>q;
while (q--){
int type; cin>>type;
if (type==1){
long long x,d,w;
cin>>x>>d>>w;
int x1=x,d1=d-1;
while (d>=0){
mut[x][d]=mut[x][d]*w%l;
x=pa[x];
d--;
}
x=x1;
while (d1>=0){
mut[x][d1]=mut[x][d1]*w%l;
x=pa[x];
d1--;
}
} else if (type==2){
long long x;
cin>>x;
long long ans=h[x]%l;
for (int i=0; i<=40; i++){
ans=ans*mut[x][i]%l;
x=pa[x];
}
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... |