제출 #853556

#제출 시각아이디문제언어결과실행 시간메모리
853556Kubogi원숭이와 사과 나무 (IZhO12_apple)C++17
100 / 100
338 ms207744 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fileio(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)

const int maxn = 1e9;

struct node {
    int val, lazy = 0;
    node *L, *R;
};

void pushdown(node *x, int l, int r) {
    if (x->lazy == 0) return;
    x->lazy = 0;

    if (x->L == nullptr) x->L = new node();
    if (x->R == nullptr) x->R = new node();

    int mid = (l+r)>>1;
    x->L->val = mid-l+1;
    x->L->lazy = 1;
    x->R->val = r-mid;
    x->R->lazy = 1;
}

void update(node *x, int l, int r, int a, int b) {
    if (r < a || b < l) return;
    if (a <= l && r <= b) {
        x->val = r-l+1;
        x->lazy = 1;
        return;
    }
    pushdown(x, l, r);

    int mid = (l+r)>>1;
    if (x->L == nullptr) x->L = new node();
    if (x->R == nullptr) x->R = new node();

    update(x->L, l, mid, a, b);
    update(x->R, mid+1, r, a, b);

    x->val = x->L->val + x->R->val;
}

int get(node *x, int l, int r, int a, int b) {
    if (r < a || b < l) return 0;
    if (a <= l && r <= b) return x->val;
    pushdown(x, l, r);

    int mid = (l+r)>>1;
    if (x->L == nullptr) x->L = new node();
    if (x->R == nullptr) x->R = new node();

    return get(x->L, l, mid, a, b) + get(x->R, mid+1, r, a, b);
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    fileio("");
    // freopen("debug.txt", "w", stderr);

    int m, c = 0; cin >> m;
    node *root = new node();
    while (m--) {
        int d, x, y;
        cin >> d >> x >> y;
        x += c; y += c;

        if (d == 2) {
            update(root, 1, maxn, x, y);
        } else {
            cout << (c = get(root, 1, maxn, x, y)) << "\n";
        }
    }

    return 0 ^ 0;
}

컴파일 시 표준 에러 (stderr) 메시지

apple.cpp: In function 'int32_t main()':
apple.cpp:5:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define fileio(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:62:5: note: in expansion of macro 'fileio'
   62 |     fileio("");
      |     ^~~~~~
apple.cpp:5:90: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define fileio(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
      |                                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:62:5: note: in expansion of macro 'fileio'
   62 |     fileio("");
      |     ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...