Submission #790531

#TimeUsernameProblemLanguageResultExecution timeMemory
790531BlagojMonkey and Apple-trees (IZhO12_apple)C++17
0 / 100
455 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define all(x) x.begin(), x.end() struct Node { int sum, lazy, tl, tr, l, r; Node() : sum(0), lazy(0), l(0), r(0) {} } tree[64 * 123456]; int cnt = 1; void push(int k) { if (tree[k].lazy) { tree[k].sum = tree[k].tr - tree[k].tl + 1; int m = (tree[k].tl + tree[k].tr) / 2; if (tree[k].l == 0) { tree[k].l = ++cnt; tree[cnt].tl = tree[k].tl; tree[cnt].tr = m; } if (tree[k].r == 0) { tree[k].r = ++cnt; tree[cnt].tl = m + 1; tree[cnt].tr = tree[k].tr; } tree[tree[k].l].lazy = tree[tree[k].r].lazy = 1; tree[k].lazy = 0; } } void update(int k, int i, int j) { push(k); if (tree[k].tr < i || tree[k].tl > j) return; if (i <= tree[k].tl && tree[k].tr <= j) { tree[k].lazy = 1; push(k); return; } int m = (tree[k].tl + tree[k].tr) / 2; if (tree[k].l == 0) { tree[k].l = ++cnt; tree[cnt].tl = tree[k].tl; tree[cnt].tr = m; } if (tree[k].r == 0) { tree[k].r = ++cnt; tree[cnt].tl = m + 1; tree[cnt].tr = tree[k].tr; } update(tree[k].l, i, j); update(tree[k].r, i, j); tree[k].sum = tree[tree[k].l].sum + tree[tree[k].r].sum; } int query(int k, int i, int j) { push(k); if (tree[k].tr < i || tree[k].tl > j) return 0; if (i <= tree[k].tl && tree[k].tr <= j) return tree[k].sum; int m = (tree[k].tl + tree[k].tr) / 2; if (tree[k].l == 0) { tree[k].l = ++cnt; tree[cnt].tl = tree[k].tl; tree[cnt].tr = m; } if (tree[k].r == 0) { tree[k].r = ++cnt; tree[cnt].tl = m + 1; tree[cnt].tr = tree[k].tr; } return query(tree[k].l, i, j) + query(tree[k].r, i, j); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int q; cin >> q; int c = 0; tree[1].sum = tree[1].lazy = 0; tree[1].tl = 1; tree[1].tr = 1e9; while (q--) { int d, x, y; cin >> d >> x >> y; if (d == 1) { c = query(1, x + c, y + c); cout << c << endl; } else update(1, x + c, y + c); } }
#Verdict Execution timeMemoryGrader output
Fetching results...