# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
969367 | tamir1 | Monkey and Apple-trees (IZhO12_apple) | C++17 | 368 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>
#define ll int
using namespace std;
ll m,i,x,y,d,c,ans;
struct node{
node *le,*ri;
ll val,lazy,l,r;
void fix(){
if(l==r){
if(lazy==1) val=1;
return;
}
ll mid=(l+r)/2;
if(le==NULL){
le=new node;
le->le=NULL;
le->ri=NULL;
le->l=l;
le->r=mid;
le->lazy=0;
le->val=0;
}
if(ri==NULL){
ri=new node;
ri->le=NULL;
ri->ri=NULL;
ri->l=mid+1;
ri->r=r;
ri->lazy=0;
ri->val=0;
}
if(lazy==1){
val=r-l+1;
le->lazy=1;
ri->lazy=1;
lazy=0;
}
}
ll query(ll x,ll y){
fix();
if(l>y || r<x) return 0;
if(l>=x && r<=y) return val;
return le->query(x,y)+ri->query(x,y);
}
void update(ll x,ll y){
fix();
if(l>y || r<x) return;
if(l>=x && r<=y){
val=r-l+1;
if(l!=r){
le->lazy=1;
ri->lazy=1;
}
return;
}
le->update(x,y);
ri->update(x,y);
val=le->val+ri->val;
}
};
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> m;
node *s = new node;
s->le=NULL;
s->ri=NULL;
s->val=0;
s->lazy=0;
s->l=1;
s->r=1e9;
for(i=1;i<=m;i++){
cin >> d >> x >> y;
if(d==1){
ans=s->query(x+c,y+c);
cout << ans << "\n";
c=ans;
}
else{
s->update(x+c,y+c);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |