Submission #1129338

#TimeUsernameProblemLanguageResultExecution timeMemory
1129338zhasynMonkey and Apple-trees (IZhO12_apple)C++20
0 / 100
198 ms63172 KiB
#include <bits/stdc++.h> #define pb push_back #define pf push_front using namespace std; #define F first #define S second typedef long long ll; #define pii pair <int, int> #define pll pair <ll, ll> typedef long double ld; const ll N = 2 * 1e6 + 100, M = 500 + 10, len = 315, inf = 1e18; const ll mod = 998244353; ll um(ll a, ll b){ return (1LL * a * b) % mod; } ll subr(ll a, ll b){ return ((1LL * a - b) % mod + mod) % mod; } ll bp(ll x, ll step){ ll res = 1; while(step){ if(step & 1) res = um(res, x); x = um(x, x); step /= 2; } return res; } ll inv(ll x){ return bp(x, mod - 2); } struct ver{ bool full; ll p[2], ans; } a[N]; ll ct; ll create(){ ll x = ct++; a[x].full = false; a[x].p[0] = a[x].p[1] = -1; a[x].ans = 0; return x; } ll sz; struct segtree { void init(ll n){ sz = 1; while(sz < n){ sz *= 2; } } void prop(ll x, ll lx, ll rx){ if(rx - lx == 1) return; if(a[x].p[0] == -1){ a[x].p[0] = create(); a[x].p[1] = create(); } if(a[x].full){ a[a[x].p[0]].full = a[a[x].p[1]].full = 1; a[a[x].p[0]].ans = a[a[x].p[1]].ans = (rx - lx) / 2; } } void upd(ll l, ll r, ll x = 0, ll lx = 0, ll rx = sz){ prop(x, lx, rx); if(lx >= r || l >= rx) return; if(l <= lx && rx <= r){ a[x].ans = rx - lx; a[x].full = true; return; } ll mid = (lx + rx) / 2; upd(l, r, a[x].p[0], lx, mid); upd(l, r, a[x].p[1], mid, rx); if(a[x].full) a[x].ans = rx - lx; else{ a[x].ans = a[a[x].p[0]].ans + a[a[x].p[1]].ans; if(a[x].ans == rx - lx) a[x].full = true; } } ll get(ll l, ll r, ll x = 0, ll lx = 0, ll rx = sz){ prop(x, lx, rx); if(lx >= r || l >= rx) return 0LL; if(l <= lx && rx <= r) return a[x].ans; ll mid = (lx + rx) / 2; ll s1 = get(l, r, a[x].p[0], lx, mid); ll s2 = get(l, r, a[x].p[1], mid, rx); return s1 + s2; } }; int main() { //ios_base::sync_with_stdio(false); //cin.tie(nullptr); //cout.tie(nullptr); ll n, C = 0; cin >> n; segtree obj; obj.init(1e10); create(); for(ll i = 0, code, x, y; i < n; i++){ cin >> code >> x >> y; x += C; y += C; if(code == 1){ ll k = obj.get(x, y + 1); cout << k << endl; C = k; } else{ obj.upd(x, y + 1); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...