# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
870640 | 2023-11-08T16:37:04 Z | NoLove | Monkey and Apple-trees (IZhO12_apple) | C++14 | 61 ms | 77276 KB |
/** * author : Lăng Trọng Đạt * created: 08-11-2023 **/ #include <bits/stdc++.h> using namespace std; #ifndef LANG_DAT #define db(...) ; #endif // LANG_DAT #define int int64_t #define mp make_pair #define f first #define s second #define pb push_back #define all(v) (v).begin(), (v).end() using pii = pair<int, int>; const int MAXN = 2e5 + 5; struct Node { int val, lazy; int lc, rc; // left child, right child int lb, rb; // left border, right border } st[4*MAXN]; ostream& operator<<(ostream& os, Node& v) { os << "[" << v.val << " " << v.lb << " " << v.rb << "]"; } int q, type, l, r; int id = 2; void extend(Node& v) { if (!v.lc) { int mid = (v.lb + v.rb) / 2; st[id].lb = v.lb; st[id].rb = mid; v.lc = id++; st[id].lb = mid + 1; st[id].rb = v.rb; v.rc = id++; } } void push(Node& v) { if (v.lazy) { if (v.lb < v.rb) { extend(v); st[v.lc].lazy = st[v.rc].lazy = 1; } v.val = v.rb - v.lb + 1; v.lazy = 0; } } void upd(Node& v) { push(v); if (v.lb > r or l > v.rb) return; else if (l <= v.lb && v.rb <= r) { v.lazy = 1; } else { extend(v); upd(st[v.lc]); upd(st[v.rc]); push(st[v.lc]); push(st[v.rc]); v.val = st[v.lc].val + st[v.rc].val; } } int get(Node& v) { push(v); if (v.lb > r or l > v.rb) return 0; else if (l <= v.lb && v.rb <= r) { return v.val; } else { extend(v); return get(st[v.lc]) + get(st[v.rc]); } } int32_t main() { cin.tie(0)->sync_with_stdio(0); if (fopen("hi.inp", "r")) { freopen("hi.inp", "r", stdin); // freopen("hi.out", "w", stdout); } st[1].lb = 1; st[1].rb = 1e9 + 50; cin >> q; int c = 0; while (cin >> type >> l >> r) { // db(l, r) l += c; r += c; if (type == 2) { upd(st[1]); } else { int tmp = get(st[1]); cout << tmp << "\n"; c = tmp; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 1 ms | 604 KB | Output is correct |
4 | Correct | 9 ms | 8796 KB | Output is correct |
5 | Correct | 11 ms | 10844 KB | Output is correct |
6 | Correct | 11 ms | 11080 KB | Output is correct |
7 | Correct | 10 ms | 10840 KB | Output is correct |
8 | Runtime error | 61 ms | 77276 KB | Execution killed with signal 11 |
9 | Halted | 0 ms | 0 KB | - |