# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
653517 | amukkalir | Monkey and Apple-trees (IZhO12_apple) | C++17 | 2065 ms | 112328 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;
const int nax = 1e7;
map<long long, bool> lazy;
map<long long, int> tree;
int m;
void cek (long long idx, int l, int r) {
if (!lazy[idx]) return;
tree[idx] = r-l+1;
int m = (l+r)>>1;
if (l!=r) {
lazy[idx<<1] = 1;
lazy[idx<<1|1] = 1;
}
lazy[idx]=0;
}
void upd (int fr, int to, long long idx = 1, int l = 1, int r = nax) {
cek(idx,l,r);
if (fr <= l && r <= to) {
lazy[idx]=1; cek(idx,l,r);
} else if (r < fr || l > to) {
return;
} else {
int m = (l+r)>>1;
upd(fr, to, idx<<1,l,m);
upd(fr, to, idx<<1|1, m+1,r);
tree[idx] = tree[idx<<1] + tree[idx<<1|1];
}
}
int get (int fr, int to, long long idx = 1, int l = 1, int r = nax) {
cek(idx, l, r);
if (!tree.count(idx)) return 0;
if (fr <= l && r <= to) return tree[idx];
else if (r < fr || l > to) return 0;
else {
int m = (l+r)>>1;
return get(fr, to, idx<<1, l, m) + get(fr, to, idx<<1|1, m+1, r);
}
}
signed main() {
scanf("%d", &m);
int c = 0;
while (m--) {
int d, x, y;
scanf("%d %d %d", &d, &x, &y);
x += c; y += c;
if (d == 1) {
int ans = get(x, y);
c = ans;
printf("%d\n",ans);
} else {
upd(x,y);
}
}
}
/*
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |