# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
333031 | nandonathaniel | Monkey and Apple-trees (IZhO12_apple) | C++14 | 175 ms | 40608 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;
int tree[3000005],lazy[3000005],ki[3000005],ka[3000005],node=2;
void pushdown(int now,int L,int R){
int mid=(L+R)/2;
if(ki[now]==0){
ki[now]=node;
node++;
}
if(ka[now]==0){
ka[now]=node;
node++;
}
tree[ki[now]]=mid-L+1;
lazy[ki[now]]=1;
tree[ka[now]]=R-mid;
lazy[ka[now]]=1;
lazy[now]=0;
}
void update(int now,int L,int R,int x,int y){
if(tree[now]==R-L+1)return;
if(L>=x && R<=y){
tree[now]=R-L+1;
lazy[now]=1;
return;
}
if(L>y || R<x)return;
int mid=(L+R)/2;
if(lazy[now])pushdown(now,L,R);
if(ki[now]==0){
ki[now]=node;
node++;
}
if(ka[now]==0){
ka[now]=node;
node++;
}
update(ki[now],L,mid,x,y);
update(ka[now],mid+1,R,x,y);
tree[now]=tree[ki[now]]+tree[ka[now]];
}
int query(int now,int L,int R,int x,int y){
if(L>=x && R<=y){
return tree[now];
}
if(L>y || R<x || now==0)return 0;
if(lazy[now])pushdown(now,L,R);
int mid=(L+R)/2;
return query(ki[now],L,mid,x,y)+query(ka[now],mid+1,R,x,y);
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int q,op,x,y,c=0;
cin >> q;
while(q--){
cin >> op >> x >> y;
x+=c;
y+=c;
if(op==1){
c=query(1,1,1e9,x,y);
cout << c << '\n';
}
else update(1,1,1e9,x,y);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |