Submission #1013357

#TimeUsernameProblemLanguageResultExecution timeMemory
101335712345678Sprinkler (JOI22_sprinkler)C++17
9 / 100
174 ms32876 KiB
#include <bits/stdc++.h> using namespace std; const int nx=2e5+5; #define ll long long ll n, u, v, q, l, h[nx], lz[nx], pa[nx], t, x, ds, w; vector<ll> d[nx]; void dfs(int u, int p) { pa[u]=p; for (auto v:d[u]) if (v!=p) dfs(v, u); } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>l; for (int i=1; i<n; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u); for (int i=1; i<=n; i++) cin>>h[i], lz[i]=1; dfs(1, 1); cin>>q; while (q--) { cin>>t; if (t==1) { cin>>x>>ds>>w; if (ds==0) h[x]=(h[x]*w)%l; else { h[x]=(h[x]*w)%l; if (pa[x]!=x) h[pa[x]]=(h[pa[x]]*w)%l; lz[x]=(lz[x]*w)%l; } } else { cin>>u; if (pa[u]==u) cout<<h[u]<<'\n'; else cout<<(h[u]*lz[pa[u]])%l<<'\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...