Submission #853556

# Submission time Handle Problem Language Result Execution time Memory
853556 2023-09-24T15:43:34 Z Kubogi Monkey and Apple-trees (IZhO12_apple) C++17
100 / 100
338 ms 207744 KB
#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;
}

Compilation message

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 time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 544 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 9 ms 4952 KB Output is correct
5 Correct 11 ms 6232 KB Output is correct
6 Correct 11 ms 5640 KB Output is correct
7 Correct 11 ms 5976 KB Output is correct
8 Correct 96 ms 43884 KB Output is correct
9 Correct 198 ms 75832 KB Output is correct
10 Correct 200 ms 83748 KB Output is correct
11 Correct 214 ms 90152 KB Output is correct
12 Correct 207 ms 92660 KB Output is correct
13 Correct 184 ms 108040 KB Output is correct
14 Correct 188 ms 111116 KB Output is correct
15 Correct 321 ms 202004 KB Output is correct
16 Correct 338 ms 203344 KB Output is correct
17 Correct 189 ms 114768 KB Output is correct
18 Correct 188 ms 114772 KB Output is correct
19 Correct 338 ms 207696 KB Output is correct
20 Correct 327 ms 207744 KB Output is correct