Submission #947804

# Submission time Handle Problem Language Result Execution time Memory
947804 2024-03-17T03:46:47 Z THXuan Monkey and Apple-trees (IZhO12_apple) C++14
100 / 100
221 ms 139860 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#define INF 1e18
using namespace std;
typedef long long ll;
const int MAXN = 5e6;
ll t[MAXN], lazy[MAXN], lf[MAXN], rg[MAXN];
int node_count = 1;

int create_node() {
    node_count++;
    return node_count;
}

void pushdown(int v, int l, int r) {
    int tm = (l + r) / 2;
    if (lf[v] == 0) lf[v] = create_node();
    if (rg[v] == 0) rg[v] = create_node();
    if (lazy[v]) {
        lazy[lf[v]] = 1;
        lazy[rg[v]] = 1;
        t[lf[v]] =  (tm - l + 1);
        t[rg[v]] = (r - tm);
        lazy[v] = 0;
    }
}
void upd(int v, int l, int r, int tl, int tr, ll val) {
    if (l > r)return;
    if (l == tl && r == tr) {
        lazy[v] = val;
        t[v] = (r - l + 1);
        return;
    }
    pushdown(v, tl, tr);
    int tm = (tl + tr) / 2;
    if (r <= tm) {
        if (lf[v] == 0) lf[v] = create_node();
        upd(lf[v], l, r, tl, tm, val);
    }
    else if (l >= tm + 1) {
        if (rg[v] == 0) rg[v] = create_node();
        upd(rg[v], l, r, tm + 1, tr, val);
    }
    else {
        if (lf[v] == 0) lf[v] = create_node();
        if (rg[v] == 0) rg[v] = create_node();
        upd(lf[v], l, tm, tl, tm, val);
        upd(rg[v], tm + 1, r, tm + 1, tr, val);
    }
    t[v] = t[lf[v]] + t[rg[v]] + lazy[v] * (tr - tl + 1);
}
ll query(int v, int tl, int tr, int l, int r) {
    if (l > r)return 0;
    if (l == tl && r == tr)return t[v];
    pushdown(v, tl, tr);
    int tm = (tl + tr) / 2;
    if (r <= tm)return query(lf[v], tl, tm, l, r);
    else if (l > tm)return query(rg[v], tm + 1, tr, l, r);
    else {
        ll left = query(lf[v], tl, tm, l, tm);
        ll right = query(rg[v], tm + 1, tr, tm + 1, r);
        return left + right;
    }
}

void solve()
{
    int m; cin >> m;
    int c = 0;
    while (m--) {
        int type; cin >> type;
        int l, r; cin >> l >> r;
        if (type == 1) {
            c = query(1, 1, 1000000005, l + c, r + c);
            cout << c << "\n";
        }
        else {
            upd(1, l + c, r + c, 1, 1000000005, 1);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;// cin>>t;
    while (t--) solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 7 ms 3420 KB Output is correct
5 Correct 9 ms 5212 KB Output is correct
6 Correct 9 ms 5212 KB Output is correct
7 Correct 12 ms 5464 KB Output is correct
8 Correct 87 ms 31060 KB Output is correct
9 Correct 147 ms 51024 KB Output is correct
10 Correct 166 ms 56384 KB Output is correct
11 Correct 173 ms 60448 KB Output is correct
12 Correct 159 ms 62284 KB Output is correct
13 Correct 145 ms 72424 KB Output is correct
14 Correct 133 ms 73300 KB Output is correct
15 Correct 221 ms 135612 KB Output is correct
16 Correct 212 ms 136908 KB Output is correct
17 Correct 145 ms 77852 KB Output is correct
18 Correct 171 ms 77900 KB Output is correct
19 Correct 212 ms 139604 KB Output is correct
20 Correct 214 ms 139860 KB Output is correct