# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
989454 | Sunbae | Monkey and Apple-trees (IZhO12_apple) | C11 | 0 ms | 0 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 <cstdio>
const int N = 1e5, M = 1e9;
int L, R, l[N<<2], r[N<<2], s[N<<2], lz[N<<2], ALLOC = 2;
void pg(int ind, int low, int high){
if(low != high){
if(!l[ind]) l[ind] = ALLOC++; if(!r[ind]) r[ind] = ALLOC++;
lz[l[ind]] = lz[r[ind]] = lz[ind];
}
lz[ind] = 0;
}
void upd(int ind, int low, int high){
if(lz[ind]){s[ind] = high-low+1; pg(ind, low, high); }
if(low > R || high < L) return;
if(L <= low && high <= R){s[ind] = high-low+1; lz[ind] = true; pg(ind, low, high); return;}
if(!l[ind]) l[ind] = ALLOC++; if(!r[ind]) r[ind] = ALLOC++;
int mid = low + ((high-low)>>1);
upd(l[ind], low, mid); upd(r[ind], mid+1, high);
s[ind] = ((l[ind])? s[l[ind]] : 0) + ((r[ind])? s[r[ind]] : 0);
}
int qry(int ind, int low, int high){
if(lz[ind]){s[ind] = high-low+1; pg(ind, low, high);}
if(low > R || high < L) return 0;
if(L <= low && high <= R) return s[ind];
int mid = low + ((high-low)>>1);
return ((l[ind])? qry(l[ind], low, mid) : 0) + ((r[ind])? qry(r[ind], mid+1, high) : 0);
}
signed main(){
int m, c = 0, d; scanf("%d", &m);
while(m--){
scanf("%d %d %d", &d, &L, &R); L += c; R += c;
if(d == 1) printf("%d\n", c = qry(1, 1, M));
else upd(1, 1, M);
}
}