# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
876788 | presko | Monkey and Apple-trees (IZhO12_apple) | C++14 | 1 ms | 348 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<iostream>
#include<bits/stdc++.h>
#define MAXN 40000010
#define BIL 1000000010
using namespace std;
struct node
{
long long l,r;
long long lazy;
void newNode()
{
lazy=0;
l=-1;
r=-1;
}
};
long long len=1;
node tree[MAXN];
void update(long long ind, long long l, long long r, long long ql, long long qr)
{
if(ql<=l && r<=qr)
{
tree[ind].lazy=1;
return;
}
long long mid=(l+r)/2;
if(ql<=mid)
{
if(tree[ind].l==-1)
{
len++;
tree[len].newNode();
tree[ind].l=len;
}
update(tree[ind].l,l,mid,ql,qr);
}
if(qr>mid)
{
if(tree[ind].r==-1)
{
len++;
tree[len].newNode();
tree[ind].r=len;
}
update(tree[ind].r,mid+1,r,ql,qr);
}
if(tree[tree[ind].l].lazy && tree[tree[ind].r].lazy)tree[ind].lazy=1;
}
long long query(long long ind, long long l, long long r, long long ql, long long qr)
{
if(r<ql || l>qr)return 0;
if(ql<=l && r<=qr && tree[ind].lazy==1)return r-l+1;
long long mid=(l+r)/2;
long long val1=0,val2=0;
if(ql<=mid)
{
if(tree[ind].l!=-1)val1= query(tree[ind].l,l,mid,ql,qr);
else if(tree[ind].lazy==1)
{
len++;
tree[len].newNode();
tree[ind].l=len;
tree[tree[ind].l].lazy=1;
val1= query(tree[ind].l,l,mid,ql,qr);
}
}
if(qr>mid)
{
if(tree[ind].r!=-1)val2= query(tree[ind].r,mid+1,r,ql,qr);
else if(tree[ind].lazy==1)
{
len++;
tree[len].newNode();
tree[ind].r=len;
tree[tree[ind].r].lazy=1;
val2= query(tree[ind].r,mid+1,r,ql,qr);
}
}
return val1+val2;
}
int main()
{
long long n,c=0;
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
tree[1].newNode();
for(long long i=0;i<n;i++)
{
long long d,x,y;
cin>>d>>x>>y;
if(d==2)
{
update(1,1,BIL,x+c,y+c);
}
else
{
long long res=query(1,1,BIL,x+c,y+c);
c=res;
cout<<res<<"\n";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |