Submission #1025239

#TimeUsernameProblemLanguageResultExecution timeMemory
1025239underwaterkillerwhaleSprinkler (JOI22_sprinkler)C++17
0 / 100
791 ms89532 KiB
#include <bits/stdc++.h> #define se second #define fs first #define pb push_back #define ll long long #define ii pair<ll,ll> #define ld long double #define SZ(v) (int)v.size() #define ALL(v) v.begin(), v.end() #define bit(msk, i) ((msk >> i) & 1) #define iter(id, v) for(auto id : v) #define rep(i,m,n) for(int i=(m); i<=(n); i++) #define reb(i,m,n) for(int i=(m); i>=(n); i--) using namespace std; mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count()); ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); } const int N = 2e5 + 7; int Mod = 1e9 + 7; const int szBL = 916; const ll INF = 1e9; const int BASE = 137; int n, Q; int a[N]; ll val[N][41], par[N]; vector<int> ke[N]; void dfs (int u, int p){ par[u] = p; iter (&v, ke[u]) { if (v != p) dfs (v, u); } } void update (int u, int d, ll w, int h = 0) { if (h > d) return; (val[u][d - h] *= w) %= Mod; update (par[u], d, w, h + 1); } ll get (int x, int de) { if (de == 41) return 1; if (x == 1) { return val[1][de]; } return val[x][de] * val[x][de + 1] % Mod * get (par[x], de + 1) % Mod; } void solution () { cin >> n >> Mod; rep (i, 1, n - 1) { int u, v; cin >> u >> v; ke[u].push_back(v); ke[v].push_back(u); } rep (i, 1, n) rep (j, 1, 41) val[i][j] = 1; rep (i, 1, n) cin >> a[i], val[i][0] = a[i]; dfs (1, 0); par[1] = 1; cin >> Q; rep (i, 1, Q) { int typ; cin >> typ; if (typ == 1) { ll x, d, w; cin >>x >> d >> w; update (x, d, w); } else { ll x; cin >> x; cout << get (x, 0) <<"\n"; } } } #define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); int main () { // file("c"); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll num_Test = 1; // cin >> num_Test; while(num_Test--) solution(); } /* */

Compilation message (stderr)

sprinkler.cpp: In function 'void solution()':
sprinkler.cpp:59:44: warning: iteration 40 invokes undefined behavior [-Waggressive-loop-optimizations]
   59 |     rep (i, 1, n) rep (j, 1, 41) val[i][j] = 1;
      |                                  ~~~~~~~~~~^~~
sprinkler.cpp:12:41: note: within this loop
   12 | #define rep(i,m,n)      for(int i=(m); i<=(n); i++)
      |                                         ^
sprinkler.cpp:59:19: note: in expansion of macro 'rep'
   59 |     rep (i, 1, n) rep (j, 1, 41) val[i][j] = 1;
      |                   ^~~
#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...