結果

問題 No.1675 Strange Minimum Query
ユーザー abc3
提出日時 2021-09-10 23:18:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,684 bytes
コンパイル時間 3,072 ms
コンパイル使用メモリ 210,312 KB
最終ジャッジ日時 2025-01-24 12:19:52
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 20
権限があれば一括ダウンロードができます

ソースコード

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=1001001001;
    const int mod=1e9+7;

    void solve(){
        int n,q;
        cin>>n>>q;
        vector<vector<int>>p(q,vector<int>(3));
        rep(i,q) {cin>>p[i][0]>>p[i][1]>>p[i][2];}
        
        sort(p.begin(),p.end());
        rep(i,q-1){
            if(p[i][0]==p[i+1][0]&&p[i][2]<p[i+1][2]){
                cout<<-1<<endl;
                return;
            }
        }
        priority_queue<P,vector<P>,greater<P>>pq;
        int pos=1;
        p.push_back({INF,INF,INF});
        vector<int>ans(n+1,1e9);
        for(auto u:p){
            int l=u[0],r=u[1],b=u[2];
            while(!pq.empty()&&pos<l){
                if(pq.top().first<pos){
                    cout<<-1<<endl;
                    return;
                }
                ans[pos]=pq.top().second;
                pq.pop();
                pos++;
            }
            pq.push({r,b});
            pos=l;
        }
        for(int i=1;i<=n;i++){
            if(i>1){cout<<" ";}
            cout<<ans[i];
        }
        cout<<endl;
    }
 
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        solve(); 

        return 0;
    }
0