Submission #654209

#TimeUsernameProblemLanguageResultExecution timeMemory
654209InternetPerson10Sprinkler (JOI22_sprinkler)C++17
100 / 100
1070 ms97148 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll MOD; vector<vector<int>> adj; vector<int> par; ll mul[200001][41]; void root(int x = 0, int p = 0) { par[x] = p; for(auto it = adj[x].begin(); it != adj[x].end(); it++) { if(*it == p) { adj[x].erase(it); break; } } for(int ch : adj[x]) { root(ch, x); } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n >> MOD; adj.resize(n); par.resize(n); for(int i = 1; i < n; i++) { int x, y; cin >> x >> y; x--; y--; adj[x].push_back(y); adj[y].push_back(x); } root(); for(int i = 0; i < n; i++) { cin >> mul[i][0]; for(int j = 1; j <= 40; j++) { mul[i][j] = 1; } } int q; cin >> q; while(q--) { int t; cin >> t; if(t == 1) { int x, d, w; cin >> x >> d >> w; x--; while(x != par[x]) { if(d >= 0) { mul[x][d] *= w; mul[x][d] %= MOD; } if(d >= 1) { mul[x][d-1] *= w; mul[x][d-1] %= MOD; } x = par[x]; d--; if(d < 0) break; } if(d >= 0) { mul[x][d] *= w; mul[x][d] %= MOD; } if(d >= 1) { mul[x][d-1] *= w; mul[x][d-1] %= MOD; } } if(t == 2) { int x; cin >> x; x--; ll ans = 1; for(int d = 0; d <= 40; d++) { ans *= mul[x][d]; ans %= MOD; if(x == par[x]) d++; x = par[x]; } 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...