# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
593501 | fdnfksd | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 252 ms | 139468 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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(!inter(l,r,i,j)) return;
if(i<=l&&r<=j)
{
st[id].val=r-l+1;
lazy[id]=1;
return;
}
ll mid=l+r>>1;
if(st[id].l==0)
{
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);
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';
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |