답안 #384626

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

using namespace std;

struct segt{
    int l, r;
    segt *a, *b;
    int val, lazy;
    segt(int vl, int vr){
        l = vl, r = vr;
        a = b = NULL;
        if(l < r){
            val = 0;
            lazy = 0;
        }
    }
    void c_child(){
        a = new segt(l, (l+r)/2), b = new segt((l+r)/2+1, r);
    }
    void push(){
        if(!a) c_child();
        if(lazy == 0) return;
        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{
            a->upd(vl, vr);
            b->upd(vl, vr);
            val = a->val + b->val;
        }
    }
    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->qry(vl, vr) + b->qry(vl, vr);
    }
};

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 Correct 1 ms 364 KB Output is correct
4 Correct 22 ms 9580 KB Output is correct
5 Correct 27 ms 11628 KB Output is correct
6 Correct 27 ms 11244 KB Output is correct
7 Correct 28 ms 11628 KB Output is correct
8 Correct 216 ms 87916 KB Output is correct
9 Correct 441 ms 152556 KB Output is correct
10 Correct 460 ms 168428 KB Output is correct
11 Correct 490 ms 180972 KB Output is correct
12 Correct 482 ms 186860 KB Output is correct
13 Correct 451 ms 217220 KB Output is correct
14 Correct 451 ms 219372 KB Output is correct
15 Runtime error 476 ms 262148 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -