Submission #892585

#TimeUsernameProblemLanguageResultExecution timeMemory
892585AiperiiiSprinkler (JOI22_sprinkler)C++14
100 / 100
1189 ms101140 KiB
#include <bits/stdc++.h> #define int long long #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back using namespace std; const int N=2e5+5; vector <int> g[N]; int p[N]; int dp[N][50]; void dfs(int v,int par){ p[v]=par; for(auto to : g[v]){ if(to!=par)dfs(to,v); } } signed main(){ int n,l; cin>>n>>l; for(int i=0;i<n-1;i++){ int u,v; cin>>u>>v; g[u].pb(v); g[v].pb(u); } for(int i=1;i<=n;i++){ for(int j=0;j<=40;j++){ dp[i][j]=1; } } dfs(1,0); vector <int> h(n+1); for(int i=1;i<=n;i++){ cin>>h[i]; dp[i][0]=h[i]; } int q;cin>>q; while(q--){ int type,v,d,x; cin>>type; if(type==1){ cin>>v>>d>>x; while(v>=1 && d>=0){ dp[v][d]=(dp[v][d])*x%l; d--; if(d<0)break; dp[v][d]=(dp[v][d])*x%l; if(p[v]!=0)v=p[v]; else{ d--; if(d<0)break; } } } else{ cin>>v; int ans=1; for(int i=0;i<=40;i++){ if(v>=1)ans=ans*dp[v][i]%l; v=p[v]; } cout<<ans<<"\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...