# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
649563 | lalala56 | Monkey and Apple-trees (IZhO12_apple) | C++14 | 389 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 M=1e9,N=1e5+9;
struct Node{
int sum,la,l,r,sl,sr;
Node(): sum(0),la(0),l(-1),r(-1){}
};
Node ST[64*N];
int n,c,cnt=2;
void tao(int id,int m){
//cout<<m<<'\n';
if(ST[id].l==-1){
ST[id].l=cnt++;
ST[ST[id].l].sl=ST[id].sl;
ST[ST[id].l].sr=m;
}
if(ST[id].r==-1){
ST[id].r=cnt++;
ST[ST[id].r].sl=m+1;
ST[ST[id].r].sr=ST[id].sr;
}
}
void down(int id){
if(ST[id].la){
ST[id].sum=ST[id].sr-ST[id].sl+1;
int m=(ST[id].sl+ST[id].sr)/2;
tao(id,m);
ST[ST[id].l].la=ST[ST[id].r].la=1;
ST[id].la=0;
}
}
void upd(int id,int l,int r){
//cout<<id<<" "<<ST[id].sl<<" "<<ST[id].sr<<'\n';
down(id);
if(l==ST[id].sl&&r==ST[id].sr){
//ST[id].sum=ST[id].sr-ST[id].sl+1;
ST[id].la=1;
down(id);
return;
}
down(id);
int m=(ST[id].sl+ST[id].sr)/2;
tao(id,m);
if(l>m)upd(ST[id].r,l,r);
else if(r<=m)upd(ST[id].l,l,r);
else{
upd(ST[id].l,l,m);
upd(ST[id].r,m+1,r);
}
down(ST[id].l);
down(ST[id].r);
ST[id].sum=ST[ST[id].l].sum+ST[ST[id].r].sum;
}
int findd(int id,int l,int r){
down(id);
if(l==ST[id].sl&&r==ST[id].sr)return ST[id].sum;
int m=(ST[id].sl+ST[id].sr)/2;
tao(id,m);
if(l>m)return findd(ST[id].r,l,r);
else if(r<=m)return findd(ST[id].l,l,r);
else return findd(ST[id].l,l,m)+findd(ST[id].r,m+1,r);
}
void giai(){
cin>>n;
int k,x,y;
c=0;
ST[1].sum=0;ST[1].la=0;
ST[1].sl=1;ST[1].sr=M;
while(n--){
cin>>k>>x>>y;
if(k==1){
c=findd(1,x+c,y+c);
cout<<c<<'\n';
}
else upd(1,x+c,y+c);
// cout<<"L\n";
}
}
int main(){
if(fopen("solve.inp","r")){
freopen("solve.inp","r",stdin);
freopen("solve.out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
giai();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |