Submission #589178

#TimeUsernameProblemLanguageResultExecution timeMemory
589178Red_InsideSprinkler (JOI22_sprinkler)C++17
100 / 100
1583 ms126468 KiB
// #include <bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back #define mp make_pair #define o cout<<"BUG"<<endl; #define FOR(i, j, n) for(int j = i; j < n; ++j) #define forn(i, j, n) for(int j = i; j <= n; ++j) #define nfor(i, j, n) for(int j = n; j >= i; --j) #define sortv(vv) sort(vv.begin(), vv.end()) #define all(v) v.begin(), v.end() #define ld long double #define ull unsigned long long using namespace std; const int maxn=2e5+100,LOG=17, mod=1e9+7; int block = 320, timer = 0; const ld EPS = 1e-18; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define bt(i) (1 << (i)) #define int ll const int inf=1e9+10; #define y1 yy #define prev pre #define pii pair <int, int> int n, q, anc[maxn], tin[maxn], tout[maxn], deep[maxn], sz[maxn], mem[maxn][42]; ll L, h[maxn]; vector <int> edge[maxn]; vector <pii> vec[maxn]; void dfs(int v, int pred = -1) { tin[v] = ++timer; vec[deep[v]].pb({tin[v], v}); for(auto to : edge[v]) { if(to == pred) continue; deep[to] = deep[v] + 1; anc[to] = v; dfs(to, v); } tout[v] = timer; } inline void update(int x, int w, int d) { if(d < 0) return; if(sz[deep[x] + d] == 0) return; // int L = lower_bound(all(vec[deep[x] + d]), mp(tin[x], 0)) - vec[deep[x] + d].begin() + 1; // int R = upper_bound(all(vec[deep[x] + d]), mp(tout[x], inf)) - vec[deep[x] + d].begin(); // upd(1, 1, sz[deep[x] + d], L, R, w, deep[x] + d); //s cout << "UPDATE " << x << " " << w << " " << d << endl; mem[x][d] = mem[x][d] * (1ll * w) % L; } main() { IOS cin >> n >> L; forn(1, i, n - 1) { int l, r; cin >> l >> r; edge[l].pb(r); edge[r].pb(l); } forn(1, i, n) cin >> h[i]; forn(1, i, n) { forn(0, j, 40) { mem[i][j] = 1; } } deep[1] = 1; dfs(1); forn(1, i, n) { sz[i] = vec[i].size(); } cin >> q; forn(1, i, q) { int ty; cin >> ty; if(ty == 1) { int x, d; int w; cin >> x >> d >> w; vector <int> ancs; int v = x; forn(0, iter, d) { ancs.pb(v); v = anc[v]; if(v == 0) break; } forn(-d, a, d) { int b = (d + a) / 2; if((int)ancs.size() > b) { // cout << "START UPDATE " << ancs[b] << " " << a << " " << b << endl; update(ancs[b], w, b - a); } else { // cout << "START UPDATE " << ancs.back() << " " << a << " " << b << endl; update(ancs.back(), w, (int)ancs.size() - 1 - a); } } } else { int x; cin >> x; // int pos = lower_bound(all(vec[deep[x]]), mp(tin[x], x)) - vec[deep[x]].begin() + 1; ll ans = h[x]; int v = x; forn(0, i, 40) { ans = ans * mem[v][i] % L; v = anc[v]; if(v == 0) break; } // cout << h[x] << " " << get(1, 1, sz[deep[x]], pos, deep[x]) << endl; cout << ans << "\n"; } } }

Compilation message (stderr)

sprinkler.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main()
      | ^~~~
#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...