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
#define ii pair<int,int>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,mod,q;
vector<int> al[200105];
int pp[200105];
int d[200105];
int memo[200105][42];
void dfs(int i,int p){
for (auto it:al[i]){
if (it==p) continue;
d[it]=d[i]+1;
pp[it]=i;
dfs(it,i);
}
}
signed main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
cin>>n>>mod;
int a,b,c;
rep(x,1,n){
cin>>a>>b;
al[a].pub(b);
al[b].pub(a);
}
int p=1;
int curr=n+1;
rep(x,0,50){
al[p].pub(curr);
al[curr].pub(p);
p=curr;
curr++;
}
pp[p]=-1;
dfs(p,-1);
rep(x,1,p+1) rep(y,0,42) memo[x][y]=1;
rep(x,1,n+1) cin>>memo[x][0];
cin>>q;
while (q--){
cin>>a;
if (a==1){
cin>>a>>b>>c;
rep(x,0,b+1){
memo[a][b-x]=memo[a][b-x]*c%mod;
a=pp[a];
}
}
else{
cin>>a;
int curr=0;
int res=1;
while (curr<41){
res=res*memo[a][curr]%mod;
res=res*memo[a][curr+1]%mod;
a=pp[a];
curr++;
}
cout<<res<<endl;
}
}
}
# | 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... |