# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
593500 | fdnfksd | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 1 ms | 340 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;
using ll=long long;
const ll maxN=5e5;
struct node
{
ll l=0,r=0, val=0;
}st[maxN*50];
ll lazy[50*maxN];
ll nnode=1;
bool inter(ll x, ll y, ll i, ll j)
{
if(y<i||j<x) return false;
return true;
}
void down(ll id,ll l, ll r)
{
if(lazy[id]>0)
{
lazy[id]=0;
ll mid=l+r>>1;
ll idl=st[id].l;
ll idr=st[id].r;
st[idl].val=mid-l+1;
lazy[idl]=1;
st[idr].val=r-mid;
lazy[idr]=1;
}
}
void update(ll id, ll l, ll r,ll i, ll j)
{
if(i<=l&&r<=j)
{
st[id].val=r-l+1;
lazy[id]=1;
return;
}
ll mid=l+r>>1;
if(inter(l,r,i,j))
{
if(st[id].l>0&&st[id].r>0)
{
down(id,l,r);
update(st[id].l,l,mid,i,j);
update(st[id].r,mid+1,r,i,j);
}
else
{
st[id].l=++nnode;
st[id].r=++nnode;
down(id,l,r);
update(st[id].l,l,mid,i,j);
update(st[id].r,mid+1,r,i,j);
}
}
//if(id==12) cout << st[id].val<<' ';
if(st[id].l>0) st[id].val=st[st[id].l].val+st[st[id].r].val;
}
ll get(ll id, ll l, ll r, ll i, ll j)
{
if(i<=l&&r<=j)
{
//cout << id<<' ';
return st[id].val;
}
ll mid=l+r>>1;
//ll mid=l+r>>1;
if(inter(l,r,i,j))
{
if(st[id].l>0&&st[id].r>0)
{
down(id,l,r);
return get(st[id].l,l,mid,i,j)+ get(st[id].r,mid+1,r,i,j);
}
else
{
st[id].l=++nnode;
st[id].r=++nnode;
down(id,l,r);
return get(st[id].l,l,mid,i,j)+ get(st[id].r,mid+1,r,i,j);
}
}
else return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll m;
cin >> m;
ll c=0;
for(int i=1;i<=m;i++)
{
ll x, y, type;
cin >> type;
if(type==2)
{
cin >> x >> y;
update(1,1,1e9,x+c,y+c);
}
else
{
cin >> x >> y;
c=get(1,1,1e9,x+c,y+c);
cout << c<<'\n';
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |