# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
653572 | amukkalir | Monkey and Apple-trees (IZhO12_apple) | C++17 | 536 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 <bits/stdc++.h>
using namespace std;
const int nax = 1e9;
struct node {
node *l_child, *r_child;
int val;
node () {
l_child=r_child=nullptr;
val=0;
}
};
node *tree, *lazy;
int m;
void verif(node* &u) {
if(!u) u=new node;
}
void cek (node* &tr, node* &lz, int l, int r) {
verif(tr); verif(lz);
if(lz->val==0)return;
tr->val=r-l+1;
if(l!=r) {
verif(lz->l_child); lz->l_child->val = 1;
verif(lz->r_child); lz->r_child->val = 1;
}
lz->val=0;
}
void upd (int fr, int to, node* &now=tree, node* &now_lazy=lazy, int l = 1, int r = nax) {
cek(now, now_lazy, l, r);
if (fr <= l && r <= to) {
now_lazy->val = 1;
cek(now, now_lazy, l, r);
} else if (r < fr || l > to) {
return;
} else {
int m = (l+r)>>1;
upd(fr, to, now->l_child, now_lazy->l_child, l, m);
upd(fr, to, now->r_child, now_lazy->r_child, m+1,r);
now->val = now->l_child->val + now->r_child->val;
}
}
int get (int fr, int to, node* &now=tree, node* &now_lazy=lazy, int l = 1, int r = nax) {
cek(now, now_lazy, l, r);
if (fr <= l && r <= to) return now->val;
else if (r < fr || l > to) return 0;
else {
int m = (l+r)>>1;
return get(fr, to, now->l_child, now_lazy->l_child, l, m) + get(fr, to, now->r_child, now_lazy->r_child, m+1, r);
}
}
signed main() {
verif(tree); verif(lazy);
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... |