結果

問題 No.1675 Strange Minimum Query
ユーザー ぷらぷら
提出日時 2021-09-10 21:34:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,788 bytes
コンパイル時間 2,787 ms
コンパイル使用メモリ 216,836 KB
実行使用メモリ 17,760 KB
最終ジャッジ日時 2023-09-02 16:08:58
合計ジャッジ時間 15,033 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 174 ms
6,412 KB
testcase_04 AC 176 ms
9,944 KB
testcase_05 AC 63 ms
10,272 KB
testcase_06 AC 201 ms
6,824 KB
testcase_07 AC 225 ms
9,744 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 331 ms
17,448 KB
testcase_14 AC 338 ms
17,500 KB
testcase_15 AC 311 ms
17,760 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 62 ms
6,360 KB
testcase_18 AC 83 ms
6,968 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 300 ms
16,600 KB
testcase_23 AC 202 ms
8,288 KB
testcase_24 AC 208 ms
11,424 KB
testcase_25 AC 138 ms
7,420 KB
testcase_26 WA -
testcase_27 AC 237 ms
16,196 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 257 ms
9,960 KB
testcase_32 AC 375 ms
17,580 KB
testcase_33 AC 372 ms
17,528 KB
testcase_34 AC 377 ms
17,760 KB
testcase_35 AC 406 ms
17,580 KB
testcase_36 AC 411 ms
17,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int inf = 1001001001;

template <typename T>
struct SegmentTree {
    int n;
    vector<T> dat;
    SegmentTree() {}
    SegmentTree(int N) {
        n = 1;
        while(n < N) {
            n *= 2;
        }
        dat.resize(2*n-1,inf);
    }
    void update(int x, T val) {
        x += (n-1);
        dat[x] = val;
        while(x > 0) {
            x = (x-1)/2;
            dat[x] = min(dat[2*x+1],dat[2*x+2]);
        }
    }
    T query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return inf;
        if(a <= l && r <= b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
    T query(int a,int b) {//[a,b)
        return query(a,b,0,0,n);
    }
};

int main() {
    int N,Q;
    cin >> N >> Q;
    vector<array<int,3>>tmp(Q);
    for(int i = 0; i < Q; i++) {
        cin >> tmp[i][1] >> tmp[i][2] >> tmp[i][0];
        tmp[i][1]--;
        tmp[i][2]--;
    }
    sort(tmp.rbegin(),tmp.rend());
    set<int>st;
    for(int i = 0; i < N; i++) {
        st.insert(i);
    }
    vector<int>ans(N,inf);
    SegmentTree<int>Seg(N);
    for(int i = 0; i < Q; i++) {
        bool flag = false;
        while (st.lower_bound(tmp[i][1]) != st.end() && *st.lower_bound(tmp[i][1]) <= tmp[i][2]) {
            ans[*st.lower_bound(tmp[i][1])] = tmp[i][0];
            Seg.update(*st.lower_bound(tmp[i][1]),tmp[i][0]);
            st.erase(st.lower_bound(tmp[i][1]));
            flag = true;
        }
        if(!flag && Seg.query(tmp[i][1],tmp[i][2]+1) != tmp[i][0]) {
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i = 0; i < N; i++) {
        cout << ans[i] << ((i+1 == N)?"\n":" ");
    }
}
0