Submission #1103101

# Submission time Handle Problem Language Result Execution time Memory
1103101 2024-10-20T05:09:03 Z Ejen Monkey and Apple-trees (IZhO12_apple) C++17
100 / 100
239 ms 110576 KB
#include <bits/stdc++.h>

#define el "\n"
#define fu(i, a, b) for (long long i = a; i <= b; ++i)
#define fd(i, a, b) for (long long i = a; i >= b; --i)
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define sz(v) (ll)(v).size()
#define mask(i) (1LL << (i))
#define bit(x, i) ((x) >> (i) & 1)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

ll Rand(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r) (rng);
}

ll last(ll msk)     {return msk & (-msk);}
ll pop_cnt(ll msk)  {return __builtin_popcountll(msk);}
ll ctz(ll msk)      {return __builtin_ctzll(msk);}
ll lg(ll msk)       {return 63 - __builtin_clzll(msk);}

template<class T1, class T2> bool minimize(T1 &a, T2 b) {
    return a > b ? a = b, 1 : 0;
}

template<class T1, class T2> bool maximize(T1 &a, T2 b) {
    return a < b ? a = b, 1 : 0;
}

template<class T> void print(T a) {
    for (auto x : a) cout << x << " ";
    cout << el;
}

template<class T> void compress(T &a) {
    sort(all(a));
    a.resize(unique(all(a)) - a.begin());
}

const long long N = 7e6 + 27, inf = 2e18, bl = 320, base = 311, mod = 1e9 + 7, lim = 30;

int q, cur;

struct SegmentTree {
    int n, l, r;
    vector<int> t, le, ri, lazy;

    SegmentTree(int _n, int _l, int _r) {
        l = _l, r = _r;
        n = _n;
        int len = N;
        t.resize(len, 0);
        le.resize(len, 0);
        ri.resize(len, 0);
        lazy.resize(len, 0);
    }

    int cur = 1;

    void addNode(int &x) {
        if (x) return;
        x = ++cur;
    }

    void down(int id, int l, int r) {
        // cout << le[id] << ' ' << ri[id] << el;
        addNode(le[id]);
        addNode(ri[id]);
        if (!lazy[id]) return;
        int mid = (l + r) / 2;
        t[le[id]] = mid - l + 1;
        t[ri[id]] = r - mid;
        lazy[le[id]] = lazy[ri[id]] = 1;
        lazy[id] = 0;
    }

    void update(int id, int l, int r, int u, int v) {
        // cout << id << ' ' << l << ' ' << r << el;
        if (r < u || l > v) return;
        if (u <= l && r <= v) {
            t[id] = r - l + 1;
            lazy[id] = 1;
            return;
        }
        down(id, l, r);
        int mid = (l + r) / 2;
        update(le[id], l, mid, u, v);
        update(ri[id], mid + 1, r, u, v);
        t[id] = t[le[id]] + t[ri[id]];
    }

    int get(int id, int l, int r, int u, int v) {
        // cout << id << ' ' << l << ' ' << r << el;
        if (!id || r < u || l > v) return 0;
        if (u <= l && r <= v) return t[id];
        down(id, l, r);
        int mid = (l + r) / 2;
        int t1 = get(le[id], l, mid, u, v);
        int t2 = get(ri[id], mid + 1, r, u, v);
        return t1 + t2;
    }
  
    int get(int u, int v) {
        return get(1, l, r, u, v);
    }

    void update(int u, int v) {
        return update(1, l, r, u, v); 
    }

};

signed main() {
     // freopen("fence.inp", "r", stdin);
     // freopen("fence.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> q;
    SegmentTree seg(q, 1, 1e9);
    // seg.update(1, 2);
    // cout << seg.cur;
    while (q--) {
        int type, l, r;
        cin >> type >> l >> r;
        l += cur;
        r += cur;
        if (type & 1) {
            cur = seg.get(l, r);
            cout << cur << el;
        }
        else seg.update(l, r);

    }
}
# Verdict Execution time Memory Grader output
1 Correct 39 ms 109896 KB Output is correct
2 Correct 41 ms 109916 KB Output is correct
3 Correct 50 ms 109896 KB Output is correct
4 Correct 50 ms 109900 KB Output is correct
5 Correct 54 ms 109896 KB Output is correct
6 Correct 54 ms 109892 KB Output is correct
7 Correct 52 ms 109936 KB Output is correct
8 Correct 96 ms 110060 KB Output is correct
9 Correct 155 ms 110260 KB Output is correct
10 Correct 167 ms 110408 KB Output is correct
11 Correct 170 ms 110416 KB Output is correct
12 Correct 173 ms 110408 KB Output is correct
13 Correct 165 ms 110548 KB Output is correct
14 Correct 160 ms 110408 KB Output is correct
15 Correct 238 ms 110576 KB Output is correct
16 Correct 233 ms 110508 KB Output is correct
17 Correct 178 ms 110500 KB Output is correct
18 Correct 174 ms 110420 KB Output is correct
19 Correct 233 ms 110408 KB Output is correct
20 Correct 239 ms 110408 KB Output is correct