# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
702764 | boyliguanhan | Monkey and Apple-trees (IZhO12_apple) | C++17 | 414 ms | 262144 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<iostream>
using namespace std;
struct node {
int v, l, r;
bool rp;
node* c[2]{ nullptr, nullptr };
node(int l, int r) : l(l), r(r), rp(false), v(0) {}
};
node* tree = new node(1, 1e9);
void pd(node* i) {
if (i->rp) {
i->v = i->r - i->l + 1;
int mid = i->r + i->l >> 1;
if (i->v > 1) {
if (!i->c[0])
i->c[0] = new node(i->l, mid);
if (!i->c[1])
i->c[1] = new node(mid + 1, i->r);
i->c[0]->rp = i->c[1]->rp = 1;
}
i->rp = 0;
}
}
void update(node* i, int l, int r) {
if (l <= i->l && i->r <= r) {
i->rp = 1, pd(i);
return;
}
pd(i);
int mid = i->l + i->r >> 1;
if (mid < r) {
if (!i->c[1])
i->c[1] = new node(mid + 1, i->r);
update(i->c[1], l, r);
}
if (l <= mid) {
if (!i->c[0])
i->c[0] = new node(i->l, mid);
update(i->c[0], l, r);
}
i->v = 0;
if (i->c[0])
pd(i->c[0]),i->v += i->c[0]->v;
if (i->c[1])
pd(i->c[1]),i->v += i->c[1]->v;
}
int query(node* i, int l, int r) {
pd(i);
if (l <= i->l && i->r <= r)
return i->v;
int mid = i->l + i->r >> 1, res = 0;
if (mid < r && i->c[1])
res = query(i->c[1], l, r);
if (l <= mid && i->c[0])
res += query(i->c[0], l, r);
return res;
}
int c;
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int q;
cin >> q;
while (q--) {
int t, x, y;
cin >> t >> x >> y;
x += c, y += c;
if (t^2)
cout << (c = query(tree, x, y)) << '\n';
else
update(tree, x, y);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |