結果

問題 No.1675 Strange Minimum Query
ユーザー beetbeet
提出日時 2021-09-10 21:29:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 3,547 bytes
コンパイル時間 2,274 ms
コンパイル使用メモリ 207,712 KB
実行使用メモリ 13,608 KB
最終ジャッジ日時 2023-09-02 15:58:09
合計ジャッジ時間 10,340 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 103 ms
8,024 KB
testcase_04 AC 101 ms
9,492 KB
testcase_05 AC 16 ms
6,556 KB
testcase_06 AC 124 ms
8,744 KB
testcase_07 AC 137 ms
10,772 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 50 ms
10,132 KB
testcase_11 AC 21 ms
8,448 KB
testcase_12 AC 54 ms
10,296 KB
testcase_13 AC 128 ms
13,608 KB
testcase_14 AC 142 ms
13,604 KB
testcase_15 AC 146 ms
13,324 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 29 ms
5,168 KB
testcase_18 AC 41 ms
5,336 KB
testcase_19 AC 57 ms
9,524 KB
testcase_20 AC 128 ms
11,236 KB
testcase_21 AC 112 ms
11,020 KB
testcase_22 AC 151 ms
12,164 KB
testcase_23 AC 116 ms
7,756 KB
testcase_24 AC 109 ms
8,596 KB
testcase_25 AC 78 ms
6,516 KB
testcase_26 AC 40 ms
6,420 KB
testcase_27 AC 102 ms
10,776 KB
testcase_28 AC 56 ms
9,276 KB
testcase_29 AC 39 ms
9,192 KB
testcase_30 AC 39 ms
6,500 KB
testcase_31 AC 153 ms
9,984 KB
testcase_32 AC 208 ms
13,236 KB
testcase_33 AC 202 ms
13,236 KB
testcase_34 AC 206 ms
13,564 KB
testcase_35 AC 172 ms
13,284 KB
testcase_36 AC 165 ms
13,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

namespace ushi{
template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  Int n;
  F f;
  T ti;
  vector<T> dat;

  SegmentTree(F f,T ti):f(f),ti(ti){}

  void init(Int n_){
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }

  void build(const vector<T> &v){
    Int n_=v.size();
    init(n_);
    for(Int i=0;i<n_;i++) dat[n+i]=v[i];
    for(Int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }

  void set_val(Int k,T x){
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }

  T query(Int a,Int b){
    if(a>=b) return ti;
    T vl=ti,vr=ti;
    for(Int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }

  template<typename C>
  Int max_right(Int s,C &check,T &acc,Int k,Int l,Int r){
    if(l+1==r){
      acc=f(acc,dat[k]);
      return check(acc)?-1:k-n;
    }
    Int m=(l+r)>>1;
    if(m<=s) return max_right(s,check,acc,(k<<1)|1,m,r);
    if(s<=l and check(f(acc,dat[k]))){
      acc=f(acc,dat[k]);
      return -1;
    }
    Int vl=max_right(s,check,acc,(k<<1)|0,l,m);
    if(~vl) return vl;
    return max_right(s,check,acc,(k<<1)|1,m,r);
  }

  // max t s.t. check(query(s,t))
  // O(\log N)
  template<typename C>
  Int max_right(Int s,C &check){
    assert(s<n and check(ti) and not check(query(s,n)));
    T acc=ti;
    return max_right(s,check,acc,1,0,n);
  }
};
}

namespace dual{
template <typename E>
struct SegmentTree{
  using H = function<E(E,E)>;
  Int n,height;
  H h;
  E ei;
  vector<E> laz;

  SegmentTree(H h,E ei):h(h),ei(ei){}

  void init(Int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    laz.assign(2*n,ei);
  }

  inline void propagate(Int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    laz[k]=ei;
  }

  inline void thrust(Int k){
    for(Int i=height;i;i--) propagate(k>>i);
  }

  void update(Int a,Int b,E x){
    if(a>=b) return;
    thrust(a+=n);
    thrust(b+=n-1);
    for(Int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
  }

  E get_val(Int a){
    thrust(a+=n);
    return laz[a];
  }

  void set_val(Int a,E x){
    thrust(a+=n);
    laz[a]=x;
  }
};
}


template<typename T>
void space(const vector<T> &vs){
  for(size_t i=0;i<vs.size();i++){
    if(i) cout<<' ';
    cout<<vs[i];
  }
  cout<<'\n';
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,q;
  cin>>n>>q;
  vector<Int> ls(q),rs(q),bs(q);
  for(Int i=0;i<q;i++) cin>>ls[i]>>rs[i]>>bs[i],ls[i]--;

  auto f=[&](Int a,Int b){return min(a,b);};
  auto h=[&](Int a,Int b){return max(a,b);};

  vector<Int> as(n,1);
  {
    dual::SegmentTree<Int> seg(h,1);
    seg.init(n);
    for(Int i=0;i<q;i++){
      seg.update(ls[i],rs[i],bs[i]);
    }
    for(Int i=0;i<n;i++) as[i]=seg.get_val(i);
  }

  {
    ushi::SegmentTree<Int> seg(f,1e9+7);
    seg.build(as);
    for(Int i=0;i<q;i++)
      if(seg.query(ls[i],rs[i])!=bs[i]) drop(-1);
  }

  space(as);
  return 0;
}
0