Submission #922592

#TimeUsernameProblemLanguageResultExecution timeMemory
922592huutuanSprinkler (JOI22_sprinkler)C++14
100 / 100
808 ms100948 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define isz(x) ((int)x.size()) #define sumof(x) accumulate(all(x), 0ll) int mod; const int N=2e5+10, MAX_DIST=40; int n, q, par[N], h[N]; int mult[N][42]; vector<int> g[N]; void dfs(int u, int p){ par[u]=p; if (p) g[u].erase(find(all(g[u]), p)); for (int v:g[u]) dfs(v, u); for (int i=0; i<=MAX_DIST+1; ++i) mult[u][i]=1; } void update(int u, int d, int w){ int lca=u; while (par[lca] && d){ mult[lca][d]=mult[lca][d]*w%mod; mult[lca][d-1]=mult[lca][d-1]*w%mod; lca=par[lca]; --d; } for (int i=d; i>=0; --i) mult[lca][i]=mult[lca][i]*w%mod; } int query(int u){ int val=h[u]; int lca=u, dist=0; while (lca && dist<=MAX_DIST){ val=1ll*val*mult[lca][dist]%mod; lca=par[lca]; ++dist; } return val; } void solve(){ cin >> n >> mod; for (int i=0; i<n-1; ++i){ int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs(1, 0); for (int i=1; i<=n; ++i) cin >> h[i]; cin >> q; while (q--){ int o; cin >> o; if (o==1){ int u, d, w; cin >> u >> d >> w; update(u, d, w); }else{ int u; cin >> u; cout << query(u) << '\n'; } } } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int ntests=1; // cin >> ntests; for (int i=1; i<=ntests; ++i) solve(); return 0; }
#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...