답안 #500748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500748 2022-01-01T07:14:58 Z Jomnoi 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;

class SegmentTree {
    public :
        int tree, lazy;
        int l, r;
        SegmentTree *L, *R;
        SegmentTree() {}
        SegmentTree(int left, int right) {
            tree = lazy = 0;
            l = left;
            r = right;
            L = R = NULL;
        }
};

void compute(SegmentTree *now) {
    int mid = (now->l + now->r) / 2;
    if(now->L == NULL) {
        now->L = new SegmentTree(now->l, mid);
    }
    if(now->R == NULL) {
        now->R = new SegmentTree(mid + 1, now->r);
    }
}

void push_lazy(SegmentTree *now) {
    if(!now->lazy) {
        return;
    }

    now->tree = now->r - now->l + 1;
    compute(now);
    if(now->l != now->r) {
        now->L->lazy = now->R->lazy = 1;
    }

    now->lazy = 0;
}

void update(SegmentTree *now, int ql, int qr) {
    push_lazy(now);
    if(now->r < ql || qr < now->l) {
        return;
    }
    if(ql <= now->l && now->r <= qr) {
        now->lazy = 1;
        push_lazy(now);
        return;
    }

    compute(now);
    update(now->L, ql, qr);
    update(now->R, ql, qr);
    now->tree = now->L->tree + now->R->tree;
}

int query(SegmentTree *now, int ql, int qr) {
    push_lazy(now);
    if(now->r < ql || qr < now->l) {
        return 0;
    }
    if(ql <= now->l && now->r <= qr) {
        return now->tree;
    }

    compute(now);
    return query(now->L, ql, qr) + query(now->R, ql, qr);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int m;
    cin >> m;
    int C;
    SegmentTree *root = new SegmentTree(1, 1e9);
    while(m--) {
        int d, x, y;
        cin >> d >> x >> y;
        if(d == 2) {
            update(root, x + C, y + C);
        }
        else {
            C = query(root, x + C, y + C);
            cout << C << '\n';
        }
    }
    return 0;
}

Compilation message

apple.cpp: In function 'int main()':
apple.cpp:86:22: warning: 'C' may be used uninitialized in this function [-Wmaybe-uninitialized]
   86 |             C = query(root, x + C, y + C);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -