結果

問題 No.318 学学学学学
ユーザー beetbeet
提出日時 2018-11-07 16:47:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 2,571 bytes
コンパイル時間 2,346 ms
コンパイル使用メモリ 209,852 KB
実行使用メモリ 6,140 KB
最終ジャッジ日時 2023-09-04 21:16:59
合計ジャッジ時間 5,602 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,376 KB
testcase_01 AC 15 ms
4,380 KB
testcase_02 AC 18 ms
4,380 KB
testcase_03 AC 12 ms
4,380 KB
testcase_04 AC 16 ms
4,380 KB
testcase_05 AC 89 ms
5,904 KB
testcase_06 AC 108 ms
6,080 KB
testcase_07 AC 94 ms
5,896 KB
testcase_08 AC 81 ms
5,900 KB
testcase_09 AC 71 ms
5,968 KB
testcase_10 AC 61 ms
5,992 KB
testcase_11 AC 89 ms
6,052 KB
testcase_12 AC 77 ms
6,004 KB
testcase_13 AC 73 ms
5,956 KB
testcase_14 AC 68 ms
6,076 KB
testcase_15 AC 64 ms
5,940 KB
testcase_16 AC 57 ms
5,948 KB
testcase_17 AC 73 ms
5,896 KB
testcase_18 AC 58 ms
6,140 KB
testcase_19 AC 73 ms
5,948 KB
testcase_20 AC 42 ms
5,964 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){}
  
  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  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]);
  }
  inline T reflect(int k){
    return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
  }
  inline void eval(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]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }
  inline void thrust(int k){
    for(int i=height;i;i--) eval(k>>i);
  }
  inline void recalc(int k){    
    while(k>>=1)
      dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
  }
  void update(int a,int b,E x){
    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);
    }
    recalc(a);
    recalc(b);
  }
  void set_val(int a,T x){
    thrust(a+=n);
    dat[a]=x;laz[a]=ei;
    recalc(a);
  }  
  T query(int a,int b){
    thrust(a+=n);
    thrust(b+=n-1);
    T vl=ti,vr=ti;
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
  T get_val(int a){
    thrust(a+=n);    
    return reflect(a);
  }
};

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];

  vector<int> ord(n);
  iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int x,int y){return a[x]<a[y];});

  auto f=[](int a,int b){return max(a,b);};
  auto g=[](int a,int b){a++;return b;};

  int ti=-1,ei=-1;
  SegmentTree<int, int> seg(f,g,g,ti,ei);
  seg.init(n);

  for(int i=0;i<n;){
    int l=n,r=0,v=a[ord[i]];
    while(i<n&&a[ord[i]]==v){
      chmin(l,ord[i]);
      chmax(r,ord[i]);
      i++;
    }
    seg.update(l,r+1,a[l]);
  }
  
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<seg.get_val(i);
  }
  cout<<endl;
  return 0;
}
0