# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
853556 | Kubogi | Monkey and Apple-trees (IZhO12_apple) | C++17 | 338 ms | 207744 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;
#define int long long
#define fileio(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
const int maxn = 1e9;
struct node {
int val, lazy = 0;
node *L, *R;
};
void pushdown(node *x, int l, int r) {
if (x->lazy == 0) return;
x->lazy = 0;
if (x->L == nullptr) x->L = new node();
if (x->R == nullptr) x->R = new node();
int mid = (l+r)>>1;
x->L->val = mid-l+1;
x->L->lazy = 1;
x->R->val = r-mid;
x->R->lazy = 1;
}
void update(node *x, int l, int r, int a, int b) {
if (r < a || b < l) return;
if (a <= l && r <= b) {
x->val = r-l+1;
x->lazy = 1;
return;
}
pushdown(x, l, r);
int mid = (l+r)>>1;
if (x->L == nullptr) x->L = new node();
if (x->R == nullptr) x->R = new node();
update(x->L, l, mid, a, b);
update(x->R, mid+1, r, a, b);
x->val = x->L->val + x->R->val;
}
int get(node *x, int l, int r, int a, int b) {
if (r < a || b < l) return 0;
if (a <= l && r <= b) return x->val;
pushdown(x, l, r);
int mid = (l+r)>>1;
if (x->L == nullptr) x->L = new node();
if (x->R == nullptr) x->R = new node();
return get(x->L, l, mid, a, b) + get(x->R, mid+1, r, a, b);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
fileio("");
// freopen("debug.txt", "w", stderr);
int m, c = 0; cin >> m;
node *root = new node();
while (m--) {
int d, x, y;
cin >> d >> x >> y;
x += c; y += c;
if (d == 2) {
update(root, 1, maxn, x, y);
} else {
cout << (c = get(root, 1, maxn, x, y)) << "\n";
}
}
return 0 ^ 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |