結果

問題 No.1675 Strange Minimum Query
ユーザー yakkiyakki
提出日時 2021-09-10 22:22:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 2,140 bytes
コンパイル時間 1,432 ms
コンパイル使用メモリ 135,772 KB
実行使用メモリ 28,256 KB
最終ジャッジ日時 2023-09-02 18:28:20
合計ジャッジ時間 12,038 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 213 ms
16,876 KB
testcase_04 AC 197 ms
17,604 KB
testcase_05 AC 48 ms
9,656 KB
testcase_06 AC 254 ms
19,328 KB
testcase_07 AC 270 ms
21,208 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 3 ms
4,368 KB
testcase_10 AC 219 ms
15,908 KB
testcase_11 AC 66 ms
10,108 KB
testcase_12 AC 249 ms
17,220 KB
testcase_13 AC 300 ms
23,444 KB
testcase_14 AC 333 ms
28,208 KB
testcase_15 AC 300 ms
28,256 KB
testcase_16 AC 1 ms
4,368 KB
testcase_17 AC 45 ms
7,148 KB
testcase_18 AC 61 ms
8,396 KB
testcase_19 AC 110 ms
13,996 KB
testcase_20 AC 172 ms
17,148 KB
testcase_21 AC 171 ms
17,984 KB
testcase_22 AC 208 ms
20,380 KB
testcase_23 AC 148 ms
13,436 KB
testcase_24 AC 144 ms
14,552 KB
testcase_25 AC 101 ms
10,664 KB
testcase_26 AC 63 ms
8,976 KB
testcase_27 AC 163 ms
17,468 KB
testcase_28 AC 94 ms
12,352 KB
testcase_29 AC 88 ms
12,824 KB
testcase_30 AC 63 ms
9,068 KB
testcase_31 AC 185 ms
16,344 KB
testcase_32 AC 262 ms
23,648 KB
testcase_33 AC 259 ms
23,560 KB
testcase_34 AC 260 ms
23,548 KB
testcase_35 AC 311 ms
24,124 KB
testcase_36 AC 314 ms
24,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<ctime>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0)

const double EPS = 1e-18;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
//using mint = modint998244353;

int dh[] = {-1,1,0,0};
int dw[] = {0,0,1,-1};

template<typename T>
vector<T> compress(vector<T> &v){
    vector<T> res = v;
    sort(res.begin(),res.end());
    res.erase(unique(res.begin(),res.end()),res.end());
    for(auto &u : v){u = lower_bound(res.begin(),res.end(),u)-res.begin();}
    return res;
}


int main(){
    int n,q; cin >> n >> q;
    vector<int> l(q),r(q),c(q);
    rep(i,q){
        cin >> l[i] >> r[i] >> c[i];
        l[i]--;
        r[i]--;
    }
    vector<int> b = c;
    compress(b);
    vector<int> re(q);
    rep(i,q) re[b[i]] = c[i];
    vector<vector<Pi>> que(q);
    rep(i,q){
        que[b[i]].push_back({l[i],r[i]});
    }
    vector<int> ans(n,1000000000);
    set<int> st;
    rep(i,n) st.insert(i);
    for(int i = q-1; i >= 0; i--){
        for(auto [l2,r2] : que[i]){
            auto p = st.lower_bound(l2);
            auto p2 = st.lower_bound(r2+1);
            if(p == p2){
                cout << -1 << endl;
                return 0;
            }
        }
        for(auto [l2,r2] : que[i]){
            auto p = st.lower_bound(l2);
            auto p2 = st.lower_bound(r2+1);
            if(p == p2) continue;
            while(p != p2){
                ans[*p] = re[i];
                p = st.erase(p);
            }
        }
    }
    rep(i,n){
        cout << ans[i];
        if(i != n-1) cout << " ";
    }
    cout << endl;
}
0