結果

問題 No.1675 Strange Minimum Query
ユーザー KudeKude
提出日時 2021-09-10 21:38:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 2,501 bytes
コンパイル時間 4,674 ms
コンパイル使用メモリ 272,864 KB
実行使用メモリ 42,180 KB
最終ジャッジ日時 2023-09-02 16:20:10
合計ジャッジ時間 13,777 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 193 ms
14,000 KB
testcase_04 AC 171 ms
17,816 KB
testcase_05 AC 21 ms
14,840 KB
testcase_06 AC 229 ms
15,832 KB
testcase_07 AC 268 ms
17,560 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 70 ms
20,132 KB
testcase_11 AC 22 ms
16,096 KB
testcase_12 AC 81 ms
22,844 KB
testcase_13 AC 146 ms
37,336 KB
testcase_14 AC 159 ms
42,180 KB
testcase_15 AC 154 ms
32,404 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 31 ms
9,700 KB
testcase_18 AC 44 ms
10,696 KB
testcase_19 AC 66 ms
23,484 KB
testcase_20 AC 146 ms
23,536 KB
testcase_21 AC 136 ms
27,816 KB
testcase_22 AC 181 ms
31,236 KB
testcase_23 AC 126 ms
14,840 KB
testcase_24 AC 123 ms
20,472 KB
testcase_25 AC 79 ms
12,944 KB
testcase_26 AC 42 ms
13,156 KB
testcase_27 AC 117 ms
27,584 KB
testcase_28 AC 56 ms
19,524 KB
testcase_29 AC 43 ms
21,292 KB
testcase_30 AC 41 ms
13,820 KB
testcase_31 AC 168 ms
18,744 KB
testcase_32 AC 239 ms
34,020 KB
testcase_33 AC 235 ms
33,428 KB
testcase_34 AC 237 ms
33,432 KB
testcase_35 AC 211 ms
31,700 KB
testcase_36 AC 210 ms
31,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

template <class S, S (*op)(S, S), S (*e)()> struct SparseTable {
    int n;
    std::vector<int> floor_lg;
    std::vector<std::vector<S>> d;
    explicit SparseTable(std::vector<S>&& a): n(a.size()), floor_lg(n + 1) {
        if (n == 0) return;
        int frog = 0;
        for(int i = 1; i <= n; frog++) {
            int j = std::min(n + 1, 2 * i);
            for(; i < j; i++) floor_lg[i] = frog;
        }
        d.resize(frog);
        d[0] = std::move(a);
        for(int p = 0, w = 1; p < frog - 1; p++, w *= 2) {
            int last = n - 2 * w;
            d[p + 1].resize(last + 1);
            for(int i = 0; i <= last; i++) d[p + 1][i] = op(d[p][i], d[p][i + w]);
        }
    }
    explicit SparseTable(const std::vector<S>& a): SparseTable(std::vector<S>(a)) {}

    S query(int l, int r) {
        assert(0 <= l && l <= r && r <= n);
        if (l >= r) return e();
        int w = r - l;
        int p = floor_lg[w];
        return op(d[p][l], d[p][r - (1 << p)]);
    }
};

int op(int x, int y) { return min(x, y); }
int e() { return 1001001001; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    VI a(n);
    struct Query {
        int l, r, b;
    };
    vector<Query> qs(q);
    vector<vector<pair<bool, int>>> events(n + 1);
    for(auto& [l, r, b]: qs) {
        cin >> l >> r >> b;
        l--;
        events[l].emplace_back(true, b);
        events[r].emplace_back(false, b);
    }
    multiset<int> st{1};
    rep(i, n) {
        for(auto [t, b]: events[i]) {
            if (t) st.insert(b);
            else st.erase(st.find(b));
        }
        a[i] = *st.rbegin();
    }
    SparseTable<int, op, e> rmq(a);
    bool ok = true;
    for(auto [l, r, b]: qs) {
        if (rmq.query(l, r) != b) {
            ok = false;
            break;
        }
    }
    if (ok) {
        rep(i, n) cout << a[i] << " \n"[i + 1 == n];
    } else {
        cout << -1 << endl;
    }
}
0