답안 #384633

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384633 2021-04-01T23:31:08 Z eyangch 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
#define endl "\n"
#define eat cin
#define moo cout

using namespace std;

struct segt{
    int l, r, mid;
    segt *a, *b;
    int val, lazy;
    segt(int vl, int vr){
        l = vl, r = vr, mid = (l+r)/2;
        a = b = NULL;
        if(l < r){
            val = 0;
            lazy = 0;
        }
    }
    void c_a(){
        a = new segt(l, mid);
    }
    void c_b(){
        b = new segt(mid+1, r);
    }
    void push(){
        if(lazy == 0) return;
        if(!a) c_a();
        if(!b) c_b();
        val = (r - l + 1) * lazy;
        if(l < r){
            a->lazy = lazy;
            b->lazy = lazy;
        }
        lazy = 0;
    }
    void upd(int vl, int vr){
        push();
        if(l > r || l > vr || r < vl) return;
        if(l >= vl && r <= vr){
            lazy = 1;
            push();
        }else{
            if(vl <= mid){
                if(!a) c_a();
                a->upd(vl, vr);
            }
            if(vr > mid){
                if(!b) c_b();
                b->upd(vl, vr);
            }
            val = (a ? a->val : 0) + (b ? b->val : 0);
        }
    }
    int qry(int vl, int vr){
        push();
        if(l > r || l > vr || r < vl) return 0;
        if(l >= vl && r <= vr) return val;
        return (a ? a->qry(vl, vr) : 0) + (b ? b->qry(vl, vr) : 0);
    }
};

segt *s;
int M;

int32_t main(){
    eat.tie(0) -> sync_with_stdio(0);
    s = new segt(1, 1e9);
    eat >> M;
    int c = 0;
    for(int i = 0; i < M; i++){
        int d, x, y; eat >> d >> x >> y;
        if(d == 1){
            c = s->qry(x+c, y+c);
            moo << c << endl;
        }else{
            s->upd(x+c, y+c);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -