Submission #574874

#TimeUsernameProblemLanguageResultExecution timeMemory
574874MateGiorbelidzeSprinkler (JOI22_sprinkler)C++14
100 / 100
987 ms95760 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define sc second #define pb push_back #define in insert ll p[201000] , h[200001] , d[201000][41]; vector<ll> g[200001]; void dfs(ll v, ll par) { for (auto k :g[v]){ if (k == par) continue; p[k] = v; dfs(k , v); } } int main () { ios::sync_with_stdio(false); cin.tie(nullptr); ll n, mod; cin>>n>>mod; for (int i = 1; i < n; i++) { ll u , v; cin>>u>>v; g[u].pb(v); g[v].pb(u); } dfs(1 , 1); p[1] = n + 1; for(int i = n + 2; i <= n + 40; i++){ p[i - 1] = i; } for (int i = 1; i <= n; i++) { cin>>h[i]; } for (int i = 1; i <= n + 40; i++) { for (int j = 0; j <= 40; j++) { d[i][j] = 1; } } ll q; cin>>q; for (int o = 1; o <= q; o++) { ll tp; cin>>tp; if (tp == 2) { ll v , ans = 1; cin>>v; ans = h[v]; ll j = 0; while (j <= 40) { ans *= d[v][j]; ans %= mod; v = p[v]; j++; } cout<<ans<<"\n"; } else { ll v, r, mul; cin>>v>>r>>mul; ll j = r; while (j > 0) { d[v][j] *= mul; d[v][j] %= mod; d[v][j - 1] *= mul; d[v][j - 1] %= mod; v = p[v]; j--; } d[v][j] *= mul; d[v][j] %= mod; } } }
#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...