結果

問題 No.1675 Strange Minimum Query
ユーザー abc3abc3
提出日時 2021-09-11 09:42:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 564 ms / 2,000 ms
コード長 2,981 bytes
コンパイル時間 3,844 ms
コンパイル使用メモリ 221,576 KB
実行使用メモリ 19,136 KB
最終ジャッジ日時 2023-09-04 17:56:42
合計ジャッジ時間 22,389 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 276 ms
12,944 KB
testcase_04 AC 259 ms
13,000 KB
testcase_05 AC 21 ms
6,216 KB
testcase_06 AC 327 ms
14,560 KB
testcase_07 AC 365 ms
16,436 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 165 ms
11,864 KB
testcase_11 AC 57 ms
7,976 KB
testcase_12 AC 184 ms
11,972 KB
testcase_13 AC 243 ms
18,796 KB
testcase_14 AC 355 ms
19,136 KB
testcase_15 AC 280 ms
18,924 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 74 ms
5,648 KB
testcase_18 AC 109 ms
6,792 KB
testcase_19 AC 162 ms
10,100 KB
testcase_20 AC 459 ms
14,972 KB
testcase_21 AC 320 ms
13,776 KB
testcase_22 AC 428 ms
15,836 KB
testcase_23 AC 318 ms
11,636 KB
testcase_24 AC 294 ms
11,368 KB
testcase_25 AC 204 ms
9,044 KB
testcase_26 AC 104 ms
7,264 KB
testcase_27 AC 287 ms
12,812 KB
testcase_28 AC 150 ms
9,820 KB
testcase_29 AC 107 ms
8,904 KB
testcase_30 AC 100 ms
7,256 KB
testcase_31 AC 421 ms
15,052 KB
testcase_32 AC 564 ms
19,008 KB
testcase_33 AC 564 ms
19,008 KB
testcase_34 AC 560 ms
18,732 KB
testcase_35 AC 478 ms
19,064 KB
testcase_36 AC 476 ms
18,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

   #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    typedef unsigned long long ull;
    using P=pair<ll,ll>;
    const ll INF=1e9;
    const int mod=1e9+7;
    
struct LazySegmentTree {
private:
    int n;
    vector<int> node, lazy;
    vector<bool> lazyFlag;

public:
    LazySegmentTree(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, INF);
        lazyFlag.resize(2*n-1, false);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }

    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = lazy[k];
            if(r - l > 1) {
                lazy[k*2+1] = lazy[k*2+2] = lazy[k];
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }

    void update(int a, int b, int x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }

    int find(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return INF;
        if(a <= l && r <= b) return node[k];
        int vl = find(a, b, 2*k+1, l, (l+r)/2);
        int vr = find(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

    void solve(){
        int n,q;
        cin>>n>>q;
        vector<vector<int>>tp(q,vector<int>(3));
        rep(i,q){
            int l,r,b;
            cin>>l>>r>>b;
            tp[i]={b,l,r};
        }
        sort(tp.begin(),tp.end());
        LazySegmentTree seg(vector<int>(n,INF));
        rep(i,q){
            int b=tp[i][0],l=tp[i][1],r=tp[i][2];
            l--;
            seg.update(l,r,b);
        }
        rep(i,q){
            int b=tp[i][0],l=tp[i][1],r=tp[i][2];
            l--;
            if(seg.find(l,r)!=b){
                cout<<-1<<endl;
                return;
            }
        }
        rep(i,n){
            if(i){cout<<" ";}
            cout<<seg.find(i,i+1);
        }
        cout<<endl;
    }
 
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        solve(); 

        return 0;
    }
0