# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
382679 | 2021-03-28T02:40:00 Z | JerryLiu06 | Monkey and Apple-trees (IZhO12_apple) | C++11 | 394 ms | 191084 KB |
#include <bits/stdc++.h> using namespace std; struct Node { int sum = 0, lazy = 0, tl, tr, l = -1, r = -1; }; int M, C, timer = 2; Node tree[8000000]; void pushdown(int x) { int mid = (tree[x].tl + tree[x].tr) / 2; if (tree[x].l == -1) { tree[x].l = timer++; tree[tree[x].l].tl = tree[x].tl; tree[tree[x].l].tr = mid; } if (tree[x].r == -1) { tree[x].r = timer++; tree[tree[x].r].tl = mid + 1; tree[tree[x].r].tr = tree[x].tr; } if (!tree[x].lazy) return ; tree[x].lazy = 0; tree[tree[x].l].sum = tree[tree[x].l].tr - tree[tree[x].l].tl + 1; tree[tree[x].l].lazy = 1; tree[tree[x].r].sum = tree[tree[x].r].tr - tree[tree[x].r].tl + 1; tree[tree[x].r].lazy = 1; } void update(int x, int l, int r) { int mid = (tree[x].tl + tree[x].tr) / 2; if (l <= tree[x].tl && tree[x].tr <= r) { tree[x].lazy = 1; tree[x].sum = tree[x].tr - tree[x].tl + 1; return ; } pushdown(x); if (mid >= l) update(tree[x].l, l, r); if (mid < r) update(tree[x].r, l, r); tree[x].sum = tree[tree[x].l].sum + tree[tree[x].r].sum; } int query(int x, int l, int r) { int mid = (tree[x].tl + tree[x].tr) / 2; if (l <= tree[x].tl && tree[x].tr <= r) return tree[x].sum; pushdown(x); int res = 0; if (mid >= l) res += query(tree[x].l, l, r); if (mid < r) res += query(tree[x].r, l, r); return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> M; tree[1].tl = 1; tree[1].tr = 1000000000; for (int i = 0; i < M; i++) { int D, X, Y; cin >> D >> X >> Y; if (D == 1) { C = query(1, X + C, Y + C); cout << C << "\n"; } else update(1, X + C, Y + C); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 127 ms | 188140 KB | Output is correct |
2 | Correct | 115 ms | 188268 KB | Output is correct |
3 | Correct | 111 ms | 188140 KB | Output is correct |
4 | Correct | 144 ms | 188524 KB | Output is correct |
5 | Correct | 126 ms | 188384 KB | Output is correct |
6 | Correct | 125 ms | 188396 KB | Output is correct |
7 | Correct | 126 ms | 188396 KB | Output is correct |
8 | Correct | 207 ms | 188780 KB | Output is correct |
9 | Correct | 318 ms | 189548 KB | Output is correct |
10 | Correct | 374 ms | 189424 KB | Output is correct |
11 | Correct | 325 ms | 189420 KB | Output is correct |
12 | Correct | 332 ms | 189420 KB | Output is correct |
13 | Correct | 303 ms | 189544 KB | Output is correct |
14 | Correct | 310 ms | 189548 KB | Output is correct |
15 | Correct | 374 ms | 190712 KB | Output is correct |
16 | Correct | 377 ms | 190956 KB | Output is correct |
17 | Correct | 310 ms | 190956 KB | Output is correct |
18 | Correct | 304 ms | 190956 KB | Output is correct |
19 | Correct | 394 ms | 191084 KB | Output is correct |
20 | Correct | 372 ms | 191084 KB | Output is correct |