結果

問題 No.1675 Strange Minimum Query
ユーザー auauaauaua
提出日時 2021-09-10 22:03:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 429 ms / 2,000 ms
コード長 2,772 bytes
コンパイル時間 2,155 ms
コンパイル使用メモリ 185,096 KB
実行使用メモリ 28,668 KB
最終ジャッジ日時 2023-09-02 17:42:39
合計ジャッジ時間 14,212 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 335 ms
19,668 KB
testcase_04 AC 290 ms
20,288 KB
testcase_05 AC 28 ms
6,848 KB
testcase_06 AC 415 ms
21,516 KB
testcase_07 AC 429 ms
24,876 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 115 ms
13,540 KB
testcase_11 AC 29 ms
8,532 KB
testcase_12 AC 125 ms
14,528 KB
testcase_13 AC 318 ms
28,668 KB
testcase_14 AC 374 ms
28,304 KB
testcase_15 AC 330 ms
28,584 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 51 ms
7,028 KB
testcase_18 AC 76 ms
8,612 KB
testcase_19 AC 96 ms
12,160 KB
testcase_20 AC 234 ms
20,548 KB
testcase_21 AC 201 ms
18,344 KB
testcase_22 AC 271 ms
22,644 KB
testcase_23 AC 233 ms
19,212 KB
testcase_24 AC 194 ms
15,884 KB
testcase_25 AC 149 ms
13,980 KB
testcase_26 AC 69 ms
8,668 KB
testcase_27 AC 177 ms
16,636 KB
testcase_28 AC 89 ms
12,416 KB
testcase_29 AC 60 ms
10,188 KB
testcase_30 AC 64 ms
8,696 KB
testcase_31 AC 300 ms
23,328 KB
testcase_32 AC 369 ms
27,924 KB
testcase_33 AC 367 ms
27,712 KB
testcase_34 AC 368 ms
27,220 KB
testcase_35 AC 329 ms
23,364 KB
testcase_36 AC 329 ms
24,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<random>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
//#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=MOD;
const ll MAX=1000000;
const double PI=acos(-1.0);
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;

//SegmentTree
template< typename Monoid >
struct SegmentTree
{
  using F = function< Monoid(Monoid, Monoid) >;
 
  int sz;
  vector< Monoid > seg;
 
  const F f;
  const Monoid M1;
 
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }
 
  void set(int k, const Monoid &x)
  {
    seg[k + sz] = x;
  }
 
  void build()
  {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
  void update(int k, const Monoid &x)
  {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
  Monoid query(int a, int b)
  {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
 
  Monoid operator[](const int &k) const
  {
    return seg[k + sz];
  }
};


void solve(){
    ll n,q;cin>>n>>q;
    vector<ll>l(q),r(q),b(q);
    vector<pair<pll,ll> >st(0);
    multiset<ll>now;
    now.insert(-1);
    rep(i,q){
        cin>>l[i]>>r[i]>>b[i];
        l[i]--;
        r[i]--;
        st.pb(mp(mp(l[i],0),b[i]));
        st.pb(mp(mp(r[i],1),b[i]));
    }
    sort(all(st));
    ll j=0;
    vector<ll>a(n);
    rep(i,n){
        while(j<q*2&&st[j].fi.fi == i && st[j].fi.se == 0){
            now.insert(-st[j].se);
            j++;
        }
        ll z=-*now.lower_bound(-inf);
        a[i]=z;
        while(j<q*2&&st[j].fi.fi == i && st[j].fi.se == 1){
            now.erase(now.find(-st[j].se));
            j++;
        }
    }
    SegmentTree<ll>seg(n,[](ll a, ll b){return min(a,b);},inf);
    rep(i,n)seg.update(i,a[i]);
    bool f=1;
    rep(i,q){
        if(seg.query(l[i],r[i]+1) != b[i])f=0;
    }
    if(f){
        rep(i,n){
            cout<<a[i];
            if(i<n-1){
                cout<<' ';
            }
        }
        cout<<endl;
    }else{
        cout<<-1<<endl;
    }
}

signed main(){
    solve();
}
0