結果

問題 No.1675 Strange Minimum Query
ユーザー umezoumezo
提出日時 2021-09-10 23:01:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 551 ms / 2,000 ms
コード長 2,701 bytes
コンパイル時間 2,599 ms
コンパイル使用メモリ 216,076 KB
実行使用メモリ 14,348 KB
最終ジャッジ日時 2023-09-02 20:51:27
合計ジャッジ時間 17,478 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 384 ms
7,796 KB
testcase_04 AC 374 ms
8,920 KB
testcase_05 AC 33 ms
7,256 KB
testcase_06 AC 454 ms
8,580 KB
testcase_07 AC 511 ms
9,904 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 3 ms
4,368 KB
testcase_10 AC 178 ms
9,372 KB
testcase_11 AC 55 ms
7,256 KB
testcase_12 AC 196 ms
10,120 KB
testcase_13 AC 459 ms
14,052 KB
testcase_14 AC 440 ms
14,060 KB
testcase_15 AC 445 ms
14,100 KB
testcase_16 AC 2 ms
4,368 KB
testcase_17 AC 75 ms
5,660 KB
testcase_18 AC 109 ms
6,052 KB
testcase_19 AC 162 ms
9,644 KB
testcase_20 AC 350 ms
10,316 KB
testcase_21 AC 318 ms
11,100 KB
testcase_22 AC 420 ms
12,424 KB
testcase_23 AC 311 ms
8,276 KB
testcase_24 AC 287 ms
9,420 KB
testcase_25 AC 201 ms
6,952 KB
testcase_26 AC 103 ms
6,464 KB
testcase_27 AC 281 ms
11,104 KB
testcase_28 AC 146 ms
8,312 KB
testcase_29 AC 108 ms
8,788 KB
testcase_30 AC 100 ms
6,424 KB
testcase_31 AC 408 ms
9,696 KB
testcase_32 AC 551 ms
14,348 KB
testcase_33 AC 549 ms
14,012 KB
testcase_34 AC 542 ms
13,996 KB
testcase_35 AC 468 ms
14,052 KB
testcase_36 AC 465 ms
14,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

template <typename X,typename M>
struct SegTreeLazy {
  using FX=function<X(X,X)>;
  using FA=function<X(X,M)>;
  using FM=function<M(M,M)>;
  int n;
  FX fx;
  FA fa;
  FM fm;
  const X ex;
  const M em;
  vector<X> dat;
  vector<M> lazy;
  SegTreeLazy(int n_,FX fx_,FA fa_,FM fm_,X ex_,M em_)
    : n(),fx(fx_),fa(fa_),fm(fm_),ex(ex_),em(em_),dat(n_*4,ex),lazy(n_*4,em) {
    int x=1;
    while (n_ > x) x *= 2;
    n=x;
  }
  void set(int i,X x) { dat[i+n-1]=x;}
  void build() {
    for (int k=n-2;k >= 0;k--) dat[k]=fx(dat[2*k+1],dat[2*k+2]);
  }
  /* lazy eval */
  void eval(int k) {
    if(lazy[k] == em) return; // 更新するものが無ければ終了
    if(k<n-1) {            // 葉でなければ子に伝搬
      lazy[k*2+1]=fm(lazy[k*2+1],lazy[k]);
      lazy[k*2+2]=fm(lazy[k*2+2],lazy[k]);
    }
    // 自身を更新
    dat[k]=fa(dat[k],lazy[k]);
    lazy[k]=em;
  }
  void update(int a,int b,M x,int k,int l,int r){
    eval(k);
    if(a<=l && r<=b){  // 完全に内側の時
      lazy[k]=fm(lazy[k],x);
      eval(k);
    }else if(a<r && l<b){                     // 一部区間が被る時
      update(a,b,x,k*2+1,l,(l+r)/2); // 左の子
      update(a,b,x,k*2+2,(l+r)/2,r); // 右の子
      dat[k]=fx(dat[k*2+1],dat[k*2+2]);
    }
  }
  void update(int a,int b,M x){update(a,b,x,0,0,n);}
  X query_sub(int a,int b,int k,int l,int r){
    eval(k);
    if(r<=a || b<=l){  // 完全に外側の時
      return ex;
    }else if(a <= l && r <= b){  // 完全に内側の時
      return dat[k];
    }else{  // 一部区間が被る時
      X vl=query_sub(a,b,k*2+1,l,(l+r)/2);
      X vr=query_sub(a,b,k*2+2,(l+r)/2,r);
      return fx(vl,vr);
    }
  }
  X query(int a,int b){return query_sub(a,b,0,0,n);}
};

int main(){
  int n,q;
  cin>>n>>q;
  vector<int> L(q),R(q),B(q);
  rep(i,q) cin>>L[i]>>R[i]>>B[i];
  vector<pair<int,pair<int,int>>> A(q);
  rep(i,q) A[i]={B[i],{L[i],R[i]}};
  sort(ALL(A));

  using X=int;
  using M=int;
  auto fx=[](X x1,X x2) -> X { return min(x1,x2);};
  auto fa=[](X x,M m) -> X { return m;};
  auto fm=[](M m1,M m2) -> M { return m2;};
  X ex=1e9+7;
  M em=1e9+7;
  SegTreeLazy<X,M> lseg(n+1,fx,fa,fm,ex,em);
  
  rep(i,q){
    lseg.update(A[i].second.first,A[i].second.second+1,A[i].first);
  }
  bool b=true;
  rep(i,q){
    if(A[i].first!=lseg.query(A[i].second.first,A[i].second.second+1)) b=false;
  }
  if(b==false){
    cout<<-1<<endl;
    return 0;
  }
  for(int i=1;i<=n;i++){
    if(i>1) cout<<" ";
    cout<<min(lseg.query(i,i+1),1000000000);
  }
  cout<<endl;

  return 0;
}
0