Submission #1129307

#TimeUsernameProblemLanguageResultExecution timeMemory
1129307zhasynMonkey and Apple-trees (IZhO12_apple)C++20
0 / 100
98 ms17516 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; // } int sz; struct segtree { vector <int> tree; vector <bool> full; void init(ll n){ sz = 1; while(sz < n){ sz *= 2; } tree.assign(2 * sz - 1, 0); full.assign(2 * sz - 1, 0); } void prop(int x, int lx, int rx){ if(rx - lx == 1) return; if(full[x]){ full[2 * x + 1] = full[2 * x + 2] = 1; tree[2 * x + 1] = tree[2 * x + 2] = (rx - lx) / 2; } } void upd(int l, int r, int x = 0, int lx = 0, int rx = sz){ prop(x, lx, rx); if(lx >= r || l >= rx) return; if(l <= lx && rx <= r){ tree[x] = rx - lx; full[x] = true; return; } int mid = (lx + rx) / 2; upd(l, r, 2 * x + 1, lx, mid); upd(l, r, 2 * x + 2, mid, rx); if(full[x]) tree[x] = rx - lx; else{ tree[x] = tree[2 * x + 1] + tree[2 * x + 2]; if(tree[x] == rx - lx) full[x] = true; } } int get(int l, int r, int x = 0, int lx = 0, int rx = sz){ prop(x, lx, rx); if(lx >= r || l >= rx) return 0LL; if(l <= lx && rx <= r) return tree[x]; int mid = (lx + rx) / 2; int s1 = get(l, r, 2 * x + 1, lx, mid); int s2 = get(l, r, 2 * x + 2, 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; //create(); obj.init(2e6); 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...