제출 #593500

#제출 시각아이디문제언어결과실행 시간메모리
593500fdnfksd원숭이와 사과 나무 (IZhO12_apple)C++14
0 / 100
1 ms340 KiB
#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';
        }
    }

}

컴파일 시 표준 에러 (stderr) 메시지

apple.cpp: In function 'void down(ll, ll, ll)':
apple.cpp:21:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |         ll mid=l+r>>1;
      |                ~^~
apple.cpp: In function 'void update(ll, ll, ll, ll, ll)':
apple.cpp:41:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |     ll mid=l+r>>1;
      |            ~^~
apple.cpp: In function 'll get(ll, ll, ll, ll, ll)':
apple.cpp:72:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   72 |     ll mid=l+r>>1;
      |            ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...