Submission #1086964

#TimeUsernameProblemLanguageResultExecution timeMemory
1086964eysbutnoWall (IOI14_wall)C++17
100 / 100
790 ms89168 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr int INF = 2e9;
class Segtree {
    struct Update {
        int min_val = 0;
        int max_val = INF;
    };
    const int sz;
    vector<Update> t;

    void apply(int v, const Update &x) {
        t[v].min_val = max(t[v].min_val, x.min_val);
        t[v].max_val = max(t[v].max_val, t[v].min_val);
        t[v].max_val = min(t[v].max_val, x.max_val);
        t[v].min_val = min(t[v].min_val, t[v].max_val);
    }

    void pushdown(int v) {
        apply(2 * v, t[v]);
        apply(2 * v + 1, t[v]);
        t[v] = Update();
    }

    void upd(int v, int l, int r, int ql, int qr, const Update &x) {
        if (qr < l || ql > r) { return; }
        if (ql <= l && r <= qr) {
            apply(v, x);
        } else {
            pushdown(v);
            int m = (l + r) / 2;
            upd(2 * v, l, m, ql, qr, x);
            upd(2 * v + 1, m + 1, r, ql, qr, x);
        }
    }

    Update qry(int v, int l, int r, int idx) {
        if (l == r) {
            return t[v];
        } else {
            pushdown(v);
            int m = (l + r) / 2;
            return (idx <= m) ? qry(2 * v, l, m, idx)
                              : qry(2 * v + 1, m + 1, r, idx);
        }
    }

  public:
    Segtree(int n) : sz(n) {
        t.assign(4 * n, Update());
    }

    void upd(int ql, int qr, const Update &x) {
        upd(1, 0, sz - 1, ql, qr, x);
    }

    Update get(int idx) {
        return qry(1, 0, sz - 1, idx);
    }
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int res[]) {
    Segtree st(n);
    for (int i = 0; i < k; i++) {
        if (op[i] == 1) {
            st.upd(left[i], right[i], {height[i], INF});
        } else {
            st.upd(left[i], right[i], {-INF, height[i]});
        }
    }
    for (int i = 0; i < n; i++) {
        res[i] = st.get(i).min_val;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...