Submission #1143105

#TimeUsernameProblemLanguageResultExecution timeMemory
1143105SulAMonkey and Apple-trees (IZhO12_apple)C++20
0 / 100
444 ms327680 KiB
#include <bits/stdc++.h>
//#pragma GCC optimize("popcnt")
#define all(a) a.begin(), a.end()
using namespace std;
using namespace chrono;

struct node {
    int l, r, sum = 0, lazy = 0;
    node *lc = nullptr, *rc = nullptr;
    node(int l, int r) : l(l), r(r) {}
    void create_kids() {
        if (l == r || lc != nullptr) return;
        int mid = (l+r)/2;
        lc = new node(l, mid);
        rc = new node(mid+1, r);
    }
    void propagate() {
        create_kids();
        if (lazy != 0) {
            sum = (r-l+1)*lazy;
            if (l != r)
                lc->lazy = lazy, rc->lazy = lazy;
            lazy = 0;
        }
    }
    void update(int ul, int ur, int x) {
        propagate();
        if (ul <= l && r <= ur) {
            lazy = x;
            propagate();
            return;
        }
        if (ur < l || r < ul) return;
        create_kids();
        lc->update(ul, ur, x);
        rc->update(ul, ur, x);
        sum = lc->sum + rc->sum;
    }
    int query(int ql, int qr) {
        propagate();
        if (ql <= l && r <= qr) return sum;
        if (qr < l || r < ql) return 0;
        return lc->query(ql, qr) +
            rc->query(ql, qr);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int n, c = 0; cin>>n;
    node* segtree = new node(0, 1'000'000'003);
    while (n--) {
        int t,l,r; cin>>t>>l>>r;
        l += c, r += c;
        if (t == 1) {
            c = segtree->query(l, r);
            cout << c << '\n';
        } else {
            segtree->update(l, r, 1);
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...