답안 #1116572

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116572 2024-11-21T20:20:24 Z boris_7 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
1 ms 336 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

struct node{
    ll l=-1,r=-1;
    ll sum = 0;
    ll rem = 0;
};

vector<node>seg(1);

void push(ll u){
    if(seg[u].l==-1){
        seg[u].l=seg.size();
        seg.emplace_back();
    }
    if(seg[u].r==-1){
        seg[u].r=seg.size();
        seg.emplace_back();
    }
    seg[seg[u].l].rem+=seg[u].rem/2;
    seg[seg[u].r].rem+=seg[u].rem/2;
    seg[seg[u].l].sum+=seg[u].rem/2;
    seg[seg[u].r].sum+=seg[u].rem/2;
    seg[u].rem=0;
}

void update(ll l,ll r,ll u,ll lx,ll rx){
    if(l>=lx && r<=rx){
        seg[u].rem+=r-l+1;
        seg[u].sum=r-l+1;
        return;
    }
    if(l>rx || r<lx){
        return;
    }
    ll mid = (l+r)/2;
    push(u);
    update(l,mid,seg[u].l,lx,rx);
    update(mid+1,r,seg[u].r,lx,rx);
    seg[u].sum=seg[seg[u].l].sum+seg[seg[u].r].sum;    
} 

ll get(ll l,ll r,ll u,ll lx,ll rx){
    if(l>=lx && r<=rx){
        return seg[u].sum;
    }
    if(l>rx || r<lx){
        return 0;
    }
    ll mid = (l+r)/2;
    push(u);
    return get(l,mid,seg[u].l,lx,rx)+get(mid+1,r,seg[u].r,lx,rx);
}

void solve(){
    ll q;
    cin>>q;
    ll c = 0;
    ll s = (1ll<<35)-1;
    while(q--){
        ll type,l,r;
        cin>>type>>l>>r;
        l--,r--;
        l+=c;
        r+=c;
        if(type==2){
            update(0,s,0,l,r);
        }
        else {
            c = get(0,s,0,l,r);
            cout<<c<<endl;
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    // ll t;cin>>t;while(t--)
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -