結果

問題 No.1675 Strange Minimum Query
ユーザー umezoumezo
提出日時 2021-09-10 22:58:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,698 bytes
コンパイル時間 2,467 ms
コンパイル使用メモリ 214,772 KB
実行使用メモリ 17,380 KB
最終ジャッジ日時 2023-09-02 20:40:54
合計ジャッジ時間 17,734 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,396 KB
testcase_01 AC 6 ms
12,412 KB
testcase_02 AC 5 ms
12,476 KB
testcase_03 AC 415 ms
16,436 KB
testcase_04 AC 384 ms
15,748 KB
testcase_05 AC 34 ms
12,632 KB
testcase_06 AC 492 ms
17,020 KB
testcase_07 AC 533 ms
17,104 KB
testcase_08 AC 5 ms
12,304 KB
testcase_09 AC 8 ms
12,380 KB
testcase_10 AC 183 ms
14,060 KB
testcase_11 AC 62 ms
12,548 KB
testcase_12 AC 204 ms
14,332 KB
testcase_13 AC 463 ms
17,292 KB
testcase_14 AC 472 ms
17,164 KB
testcase_15 WA -
testcase_16 AC 5 ms
12,268 KB
testcase_17 AC 88 ms
12,900 KB
testcase_18 AC 126 ms
13,416 KB
testcase_19 AC 172 ms
13,364 KB
testcase_20 AC 371 ms
15,708 KB
testcase_21 AC 332 ms
14,852 KB
testcase_22 AC 434 ms
15,848 KB
testcase_23 AC 342 ms
15,644 KB
testcase_24 AC 311 ms
15,056 KB
testcase_25 AC 220 ms
14,524 KB
testcase_26 AC 114 ms
13,260 KB
testcase_27 AC 295 ms
14,580 KB
testcase_28 AC 156 ms
13,476 KB
testcase_29 AC 117 ms
12,844 KB
testcase_30 AC 110 ms
13,268 KB
testcase_31 AC 434 ms
16,556 KB
testcase_32 AC 580 ms
17,100 KB
testcase_33 AC 581 ms
17,056 KB
testcase_34 AC 573 ms
17,304 KB
testcase_35 AC 491 ms
17,068 KB
testcase_36 AC 491 ms
17,380 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=1000000000;
  M em=1000000000;
  SegTreeLazy<X,M> lseg(300000,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<<lseg.query(i,i+1);
  }
  cout<<endl;

  return 0;
}
0