結果

問題 No.1675 Strange Minimum Query
ユーザー auauaauaua
提出日時 2021-09-10 22:00:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,774 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 184,080 KB
実行使用メモリ 34,116 KB
最終ジャッジ日時 2023-09-02 17:32:43
合計ジャッジ時間 11,202 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 305 ms
24,092 KB
testcase_04 AC 264 ms
23,840 KB
testcase_05 AC 28 ms
7,248 KB
testcase_06 AC 368 ms
27,288 KB
testcase_07 AC 383 ms
29,564 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 304 ms
33,036 KB
testcase_14 AC 360 ms
32,280 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,372 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

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