답안 #790530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790530 2023-07-22T19:43:21 Z Blagoj 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
1769 ms 185740 KB
#include <bits/stdc++.h>
#include <fstream>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()

ifstream fin("f.in");
ofstream fout("f.out");

struct Node {
    int sum, lazy, tl, tr, l, r;
    Node() : sum(0), lazy(0), l(0), r(0) {}
} tree[64 * 123456];

int cnt = 1;

void push(int k) {
    if (tree[k].lazy) {
        tree[k].sum = tree[k].tr - tree[k].tl + 1;
        int m = (tree[k].tl + tree[k].tr) / 2; 
        if (tree[k].l == 0) {
            tree[k].l = ++cnt;
            tree[cnt].tl = tree[k].tl;
            tree[cnt].tr = m;
        }
        if (tree[k].r == 0) {
            tree[k].r = ++cnt;
            tree[cnt].tl = m + 1;
            tree[cnt].tr = tree[k].tr;
        }
        tree[tree[k].l].lazy = tree[tree[k].r].lazy = 1;
        tree[k].lazy = 0;
    }
}

void update(int k, int i, int j) {
    push(k);
    if (tree[k].tr < i || tree[k].tl > j) return;
    if (i <= tree[k].tl && tree[k].tr <= j) {
        tree[k].lazy = 1;
        push(k);
        return;
    }
    int m = (tree[k].tl + tree[k].tr) / 2;
    if (tree[k].l == 0) {
        tree[k].l = ++cnt;
        tree[cnt].tl = tree[k].tl;
        tree[cnt].tr = m;
    }
    if (tree[k].r == 0) {
        tree[k].r = ++cnt;
        tree[cnt].tl = m + 1;
        tree[cnt].tr = tree[k].tr;
    }
    update(tree[k].l, i, j);
    update(tree[k].r, i, j);
    push(tree[k].l);
    push(tree[k].r);
    tree[k].sum = tree[tree[k].l].sum + tree[tree[k].r].sum;
}

int query(int k, int i, int j) {
    push(k);
    if (tree[k].tr < i || tree[k].tl > j) return 0;
    if (i <= tree[k].tl && tree[k].tr <= j) return tree[k].sum;
    int m = (tree[k].tl + tree[k].tr) / 2;
    if (tree[k].l == 0) {
        tree[k].l = ++cnt;
        tree[cnt].tl = tree[k].tl;
        tree[cnt].tr = m;
    }
    if (tree[k].r == 0) {
        tree[k].r = ++cnt;
        tree[cnt].tl = m + 1;
        tree[cnt].tr = tree[k].tr;
    }
    return query(tree[k].l, i, j) + query(tree[k].r, i, j);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    fin >> q;
    int c = 0;
    tree[1].sum = tree[1].lazy = 0;
    tree[1].tl = 1;
    tree[1].tr = 1e9;
    while (q--) {
        int d, x, y;
        fin >> d >> x >> y;
        if (d == 1) {
            c = query(1, x + c, y + c);
            fout << c << endl;
        }
        else update(1, x + c, y + c);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1769 ms 185740 KB Output isn't correct
2 Halted 0 ms 0 KB -