Submission #314466

# Submission time Handle Problem Language Result Execution time Memory
314466 2020-10-20T02:18:23 Z Vince729 Monkey and Apple-trees (IZhO12_apple) C++11
100 / 100
51 ms 3096 KB
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;

typedef long long ll;

const int MAXN = 100003;
const int MOD = 1000000007;

struct Node {
    int l, r, sum;
    bool z;
    Node *ln, *rn;

    Node(int _l, int _r): l(_l), r(_r), sum(0), z(0), ln(nullptr), rn(nullptr) {}

    void upd(int a, int b) {
        if (z) return;
        if (a <= l && b >= r) {
            sum = r-l+1;
            z = true;
        } else {
            int mid = (l+r)/2;
            if (a <= mid) {
                if (!ln) ln = new Node(l, mid);
                ln->upd(a, b);
            }
            if (b > mid) {
                if (!rn) rn = new Node(mid+1, r);
                rn->upd(a, b);
            }
            sum = 0;
            if (ln) sum += ln->sum;
            if (rn) sum += rn->sum;
        }
    }

    int qry(int a, int b) {
        if (b < l || a > r) return 0;
        if (a <= l && b >= r) return sum;
        if (z) return min(b, r)-max(a, l)+1;
        int ret = 0;
        if (ln) ret += ln->qry(a, b);
        if (rn) ret += rn->qry(a, b);
        return ret;
    }
};

int m;
Node root(1, 1000000000);

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> m;
    int c = 0;
    while (m--) {
        int d, x, y; cin >> d >> x >> y;
        if (d == 2) {
            root.upd(x+c, y+c);
        } else {
            c = root.qry(x+c, y+c);
            cout << c << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 4 ms 560 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 22 ms 1400 KB Output is correct
9 Correct 44 ms 2552 KB Output is correct
10 Correct 42 ms 2552 KB Output is correct
11 Correct 41 ms 2560 KB Output is correct
12 Correct 40 ms 2552 KB Output is correct
13 Correct 50 ms 2936 KB Output is correct
14 Correct 51 ms 2844 KB Output is correct
15 Correct 42 ms 3064 KB Output is correct
16 Correct 43 ms 3068 KB Output is correct
17 Correct 36 ms 2936 KB Output is correct
18 Correct 36 ms 2936 KB Output is correct
19 Correct 40 ms 3084 KB Output is correct
20 Correct 41 ms 3096 KB Output is correct