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;
#define int long long
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,l;
cin >> n >> l;
vector<vector<int>> adj(n+41);
for(int i=1;i<n;i++){
int a,b;cin>>a>>b;
adj[a].emplace_back(b);
adj[b].emplace_back(a);
}
for(int i=n+1;i<=n+40;i++){
adj[i].emplace_back(i-1);
adj[i-1].emplace_back(i);
}
vector<int> H(n+41);
vector<vector<int>> lazy(n+41,vector<int>(42,1));
vector<int> p(n+41);
for(int i=1;i<=n;i++)cin>>H[i];
function<void(int,int)> dfs = [&](int x,int par){
p[x] = par;
for(int&i:adj[x])if(i!=par)dfs(i,x);
};
dfs(n+40,0);
auto getoffset = [&](int x){
int ans = 1;
for(int i=0;i<=40;i++){
ans=(((ans*lazy[x][i])%l)*lazy[x][i+1])%l;
x = p[x];
if(x==0)break;
}
return ans;
};
auto makeoffset = [&](int x,int w,int d){
for(int i=d;i>=0;i--){
lazy[x][i] = (lazy[x][i]*w)%l;
x = p[x];
if(x==0)break;
}
};
int q;
cin >> q;
for(int i=1;i<=q;i++){
int type;cin>>type;
if(type==1){
int x,d,w;cin>>x>>d>>w;
makeoffset(x,w,d);
} else {
int x;cin>>x;
cout << (H[x]*getoffset(x))%l << '\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... |