Submission #574870

#TimeUsernameProblemLanguageResultExecution timeMemory
574870MateGiorbelidzeSprinkler (JOI22_sprinkler)C++14
0 / 100
737 ms91988 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][40]; 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; } } }

Compilation message (stderr)

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:48:15: warning: iteration 40 invokes undefined behavior [-Waggressive-loop-optimizations]
   48 |       d[i][j] = 1;
      |       ~~~~~~~~^~~
sprinkler.cpp:47:24: note: within this loop
   47 |      for (int j = 0; j <= 40; j++) {
      |                      ~~^~~~~
sprinkler.cpp:68:18: warning: iteration 40 invokes undefined behavior [-Waggressive-loop-optimizations]
   68 |     ans *= d[v][j];
      |            ~~~~~~^
sprinkler.cpp:66:13: note: within this loop
   66 |    while (j <= 40) {
      |           ~~^~~~~
#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...