# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
382606 | JerryLiu06 | Monkey and Apple-trees (IZhO12_apple) | C++11 | 545 ms | 262148 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct Node {
int sum, l, r, lazy; Node *lc, *rc;
Node(int L, int R): sum(0), lazy(0), l(L), r(R), lc(nullptr), rc(nullptr) {}
void pushdown() {
if (!lazy) return ; sum = r - l + 1; int mid = (l + r) / 2;
if (l < r) {
if (!lc) lc = new Node(l, mid); lc -> lazy = 1; lc -> sum = mid - l + 1;
if (!rc) rc = new Node(mid + 1, r); rc -> lazy = 1; rc -> sum = r - mid;
}
lazy = 0;
}
void update(int tl, int tr) { int mid = (l + r) / 2;
pushdown(); if (tl <= l && r <= tr) { lazy = 1; pushdown(); return ; }
if (tl > mid) { if (!rc) rc = new Node(mid + 1, r); rc -> update(tl, tr); }
else if (tr <= mid) { if (!lc) lc = new Node(l, mid); lc -> update(tl, tr); }
else { if (!lc) lc = new Node(l, mid); lc -> update(tl, tr); if (!rc) rc = new Node(mid + 1, r); rc -> update(tl, tr); }
sum = 0; if (lc) sum += lc -> sum; if (rc) sum += rc -> sum;
}
int query(int tl, int tr) { int mid = (l + r) / 2;
pushdown(); if (l > tr || r < tl) return 0; if (tl <= l && r <= tr) return sum;
return ((lc) ? (lc -> query(tl, tr)) : 0) + ((rc) ? (rc -> query(tl, tr)) : 0);
}
};
int M, C; Node root(1, 1000000000);
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> M;
for (int i = 0; i < M; i++) { int D, X, Y; cin >> D >> X >> Y;
if (D == 1) { C = root.query(X + C, Y + C); cout << C << "\n"; }
if (D == 2) root.update(X + C, Y + C);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |