Submission #1188577

#TimeUsernameProblemLanguageResultExecution timeMemory
1188577colonelsvenMonkey and Apple-trees (IZhO12_apple)C++20
0 / 100
439 ms327680 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

struct Vertex {
    int low, high, sum = 0, lazy = 0;
    
    Vertex *left_child = nullptr, *right_child = nullptr;

    Vertex(int l, int r) {
        low = l;
        high = r;
    }

    void propagate() {
        sum = max(sum, (lazy * (high - low + 1)));
        if (low != high) {
            int mid = (low + high) / 2;
            if (!left_child) {
                left_child = new Vertex(low, mid);
                right_child = new Vertex(mid + 1, high);
            }
            left_child->lazy = max(lazy, left_child->lazy);
            right_child->lazy = max(lazy, right_child->lazy);
        }
        lazy = 0;
    }

    int query(int l, int r) {
        propagate();
        if (low >= l && high <= r) return sum;
        else if (low > r || high < l || low > high) return 0;
        else {
            int mid = (low + high) / 2;
            return left_child->query(l, r) + right_child->query(l, r);
        }
    }

    void update(int l, int r) {
        propagate();
        if (low >= l && high <= r) {
            lazy = 1;
            propagate();
        }
        else if (low > r || high < l || low > high) return;
        else {
            int mid = (low + high) / 2;
            left_child->update(l, r);
            right_child->update(l, r);
            sum = left_child->sum + right_child->sum;
        }
    }
};



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int q;
    cin >> q;

    Vertex seg = Vertex(1, 1e9);

    int c = 0;

    while (q--) {
        int type, l, r;
        cin >> type >> l >> r;
        l += c; r += c;

        if (type == 1) {
            c = seg.query(l, r);
            printf("%i\n", c);
        }
        else {
            seg.update(l, r);
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...