# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
168071 | GioChkhaidze | Monkey and Apple-trees (IZhO12_apple) | C++14 | 537 ms | 165496 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>
#define Tree int &h,int l,int r
#define Left v[h][1],l,(l+r)/2
#define Right v[h][2],(l+r)/2+1,r
using namespace std;
const int N=5000006;
int nodes=1,n,L,R,ANS,Root,type;
int v[2*N][5];
inline void Shift(int h,int l,int r) {
if (!v[h][4]) return ;
v[h][0]=r-l+1;
if (l!=r) {
if (!v[h][1]) v[h][1]=++nodes;
if (!v[h][2]) v[h][2]=++nodes;
v[v[h][1]][4]=1,v[v[h][2]][4]=1;
}
v[h][4]=0;
}
inline int Get (Tree) {
if (!h) h=++nodes;
Shift(h,l,r);
if (r<L || R<l) return 0;
if (L<=l && r<=R) return v[h][0];
return Get(Left)+Get(Right);
}
inline void Upd (Tree) {
if (!h) h=++nodes;
Shift(h,l,r);
if (r<L || R<l) return ;
if (L<=l && r<=R) { v[h][4]=1; Shift(h,l,r); return ; }
Upd(Left),Upd(Right);
v[h][0]=v[v[h][1]][0]+v[v[h][2]][0];
}
main () {
scanf("%d",&n);
for (int i=1; i<=n; i++) {
scanf("%d %d %d",&type,&L,&R);
L+=ANS,R+=ANS,Root=1;
if (type==1) {
ANS=Get(Root,1,1e9);
printf("%d\n",ANS);
}
else Upd(Root,1,1e9);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |