# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
521164 | Jomnoi | Monkey and Apple-trees (IZhO12_apple) | C++17 | 539 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>
#define DEBUG 0
using namespace std;
class Node {
public :
int v;
int l, r;
bool lazy;
Node *L, *R;
Node(const int &_l, const int &_r) : l(_l), r(_r), v(0), lazy(false), L(NULL), R(NULL) {}
};
void check(Node *&node, const int &l, const int &r) {
if(node != NULL) {
return;
}
node = new Node(l, r);
}
void push_lazy(Node *&node) {
if(node->lazy == false) {
return;
}
node->v = node->r - node->l + 1;
if(node->l != node->r) {
int mid = (node->l + node->r) / 2;
check(node->L, node->l, mid);
check(node->R, mid + 1, node->r);
node->L->lazy = true;
node->R->lazy = true;
}
node->lazy = false;
}
void update(Node *&node, const int &ql, const int &qr) {
push_lazy(node);
if(ql == node->l and node->r == qr) {
node->lazy = true;
push_lazy(node);
return;
}
int mid = (node->l + node->r) / 2;
check(node->L, node->l, mid);
check(node->R, mid + 1, node->r);
if(qr <= mid) {
update(node->L, ql, qr);
}
else if(mid < ql) {
update(node->R, ql, qr);
}
else {
update(node->L, ql, mid);
update(node->R, mid + 1, qr);
}
push_lazy(node->L);
push_lazy(node->R);
node->v = node->L->v + node->R->v;
}
int query(Node *node, int ql, int qr) {
if(node == NULL) {
return 0;
}
push_lazy(node);
if(ql == node->l and node->r == qr) {
return node->v;
}
int mid = (node->l + node->r) / 2;
if(qr <= mid) {
return query(node->L, ql, qr);
}
else if(mid < ql) {
return query(node->R, ql, qr);
}
return query(node->L, ql, mid) + query(node->R, mid + 1, qr);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int m;
cin >> m;
int C = 0;
Node *root = new Node(1, 1e9);
while(m--) {
int d, x, y;
cin >> d >> x >> y;
if(d == 1) {
C = query(root, x + C, y + C);
cout << C << '\n';
}
else {
update(root, x + C, y + C);
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |