# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1114418 | nikolashami | Monkey and Apple-trees (IZhO12_apple) | C++17 | 172 ms | 97608 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 N=3e6;
int lc[N],rc[N],ans,m,c,id=1;
struct{int s=0,lz=0;}st[N];
void make(int&node){
if(!node)node=++id;
}
void push(int node,int l,int r){
if(!st[node].lz)
return;
int mid=(l+r)/2;
st[lc[node]].s=mid-l+1;
st[rc[node]].s=r-mid;
st[lc[node]].lz=1;
st[rc[node]].lz=1;
st[node].lz=0;
}
void qry(int l,int r,int node=1,int tl=1,int tr=1e9){
if(tl>=l&&tr<=r){
ans+=st[node].s;
return;
}
make(lc[node]);
make(rc[node]);
push(node,tl,tr);
int mid=(tl+tr)/2;
if(mid>=l)qry(l,r,lc[node],tl,mid);
if(mid+1<=r)qry(l,r,rc[node],mid+1,tr);
}
void upd(int l,int r,int node=1,int tl=1,int tr=1e9){
if(tl>=l&&tr<=r){
st[node].s=tr-tl+1;
st[node].lz=1;
return;
}
make(lc[node]);
make(rc[node]);
push(node,tl,tr);
int mid=(tl+tr)/2;
if(mid>=l)upd(l,r,lc[node],tl,mid);
if(mid+1<=r)upd(l,r,rc[node],mid+1,tr);
st[node].s=st[lc[node]].s+st[rc[node]].s;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>m;
while(m--){
int tp,l,r;
cin>>tp>>l>>r;
if(tp==1){
ans=0;
qry(l+c,r+c);
c=ans;
cout<<ans<<'\n';
}else
upd(l+c,r+c);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |