結果

問題 No.1675 Strange Minimum Query
ユーザー merom686merom686
提出日時 2021-09-10 21:53:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 2,195 bytes
コンパイル時間 2,608 ms
コンパイル使用メモリ 212,024 KB
実行使用メモリ 21,348 KB
最終ジャッジ日時 2023-09-02 17:02:20
合計ジャッジ時間 11,123 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 175 ms
13,424 KB
testcase_04 AC 155 ms
12,396 KB
testcase_05 AC 10 ms
4,868 KB
testcase_06 AC 225 ms
15,156 KB
testcase_07 AC 237 ms
15,812 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 50 ms
7,304 KB
testcase_11 AC 14 ms
4,564 KB
testcase_12 AC 56 ms
7,560 KB
testcase_13 AC 143 ms
21,308 KB
testcase_14 AC 158 ms
21,228 KB
testcase_15 AC 144 ms
21,348 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 27 ms
5,152 KB
testcase_18 AC 40 ms
5,984 KB
testcase_19 AC 49 ms
6,940 KB
testcase_20 AC 127 ms
12,204 KB
testcase_21 AC 108 ms
10,900 KB
testcase_22 AC 145 ms
13,228 KB
testcase_23 AC 127 ms
11,492 KB
testcase_24 AC 105 ms
10,296 KB
testcase_25 AC 81 ms
8,564 KB
testcase_26 AC 35 ms
5,876 KB
testcase_27 AC 97 ms
9,920 KB
testcase_28 AC 45 ms
7,000 KB
testcase_29 AC 29 ms
5,984 KB
testcase_30 AC 33 ms
5,624 KB
testcase_31 AC 164 ms
14,284 KB
testcase_32 AC 202 ms
16,560 KB
testcase_33 AC 199 ms
16,668 KB
testcase_34 AC 205 ms
16,640 KB
testcase_35 AC 164 ms
11,916 KB
testcase_36 AC 165 ms
11,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <class T>
struct SegmentTree {
    SegmentTree(int n) : n(n) {
        for (m = 2; m < n; m *= 2);
        t = vector<T>(m + n + n % 2);
    }
    T &operator[](int i) {
        return t[m + i];
    }
    const T &root() const {
        return t[1];
    }
    void build() {
        for (int i = (n - 1 + m) / 2; i > 0; i--) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    void update(int i, const T &o) {
        for (t[i += m] = o; i /= 2, i > 0;) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    T query(int l, int r) {
        T o0, o1;
        for (l += m, r += m; l < r; l /= 2, r /= 2) {
            if (l & 1) o0 = o0 * t[l++];
            if (r & 1) o1 = t[--r] * o1;
        }
        return o0 * o1;
    }
    vector<T> t;
    int n, m;
};
struct Min {
    constexpr Min() : v(1 << 30) {}
    Min(int v) : v(v) {}
    Min operator*(const Min &o) const {
        return min(v, o.v);
    }
    int v;
};

struct P {
    bool operator<(const P &p) const {
        return i < p.i;
    }
    int i, b, s;
};

struct Q {
    int l, r, b;
};

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

    int n, q;
    cin >> n >> q;

    vector<P> p(q * 2);
    vector<Q> x(q);
    for (int i = 0; i < q; i++) {
        int l, r, b;
        cin >> l >> r >> b;
        l--;

        p[i * 2 + 0] = { l, b, 0 };
        p[i * 2 + 1] = { r, b, 1 };
        x[i] = { l, r, b };
    }
    sort(p.begin(), p.end());

    SegmentTree<Min> st(n);

    multiset<int> ms;
    int j = 0;
    for (int i = 0; i < n; i++) {
        while (j < q * 2 && p[j].i <= i) {
            if (p[j].s == 0) {
                ms.insert(p[j++].b);
            } else {
                ms.erase(ms.find(p[j++].b));
            }
        }
        auto it = ms.end();
        int t = 1;
        if (!ms.empty()) t = *--it;
        st[i].v = t;
    }
    st.build();

    for (int i = 0; i < q; i++) {
        const auto &[l, r, b] = x[i];
        if (st.query(l, r).v != b) {
            cout << -1 << endl;
            exit(0);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << st[i].v << " \n"[i == n - 1];
    }

    return 0;
}
0