# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
987127 | Sunbae | Monkey and Apple-trees (IZhO12_apple) | C++17 | 418 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 <stdio.h>
struct Vertex{
Vertex *l = nullptr, *r = nullptr;
int low, high, sum = 0; bool op = false;
Vertex(int L, int R){low = L; high = R;}
~Vertex(){if(l) delete l; if(r) delete r;}
void propagate(){
if(low != high){
int mid = low + ((high-low)>>1);
if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
l->op = r->op = true;
}
op = false;
}
void upd(int L, int R){
if(op){sum = (high-low+1); propagate();}
if(low > R || high < L) return;
if(L <= low && high <= R){
sum = high-low+1; op = true; propagate(); return;
}
int mid = low + ((high-low)>>1);
if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
l->upd(L, R); r->upd(L, R);
sum = ((l)? l->sum : 0) + ((r)? r->sum : 0);
}
int qry(int L, int R){
if(op){sum = (high-low+1); propagate();}
if(low > R || high < L) return 0;
if(L <= low && high <= R) return sum;
int mid = low + ((high-low)>>1);
if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
return ((l)? l->qry(L, R) : 0) + ((r)? r->qry(L, R) : 0);
}
};
signed main(){
int q, c = 0; scanf("%d", &q);
Vertex* seg = new Vertex(1, 1e9);
while(q--){
int t, x, y; scanf("%d %d %d", &t, &x, &y);
if(t == 1){
printf("%d\n", c = seg->qry(x+c, y+c));
}else{
seg->upd(x+c, y+c);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |