結果

問題 No.318 学学学学学
ユーザー hashiryohashiryo
提出日時 2019-05-30 19:22:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 3,269 bytes
コンパイル時間 1,645 ms
コンパイル使用メモリ 181,632 KB
実行使用メモリ 17,320 KB
最終ジャッジ日時 2023-10-17 18:54:07
合計ジャッジ時間 5,415 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,528 KB
testcase_01 AC 20 ms
6,032 KB
testcase_02 AC 23 ms
6,296 KB
testcase_03 AC 15 ms
4,976 KB
testcase_04 AC 20 ms
6,032 KB
testcase_05 AC 150 ms
17,320 KB
testcase_06 AC 142 ms
13,160 KB
testcase_07 AC 114 ms
11,576 KB
testcase_08 AC 87 ms
10,520 KB
testcase_09 AC 66 ms
9,728 KB
testcase_10 AC 47 ms
8,936 KB
testcase_11 AC 152 ms
17,320 KB
testcase_12 AC 99 ms
13,160 KB
testcase_13 AC 82 ms
11,576 KB
testcase_14 AC 67 ms
10,520 KB
testcase_15 AC 54 ms
9,728 KB
testcase_16 AC 38 ms
8,936 KB
testcase_17 AC 87 ms
13,160 KB
testcase_18 AC 69 ms
13,160 KB
testcase_19 AC 87 ms
13,160 KB
testcase_20 AC 36 ms
9,144 KB
testcase_21 AC 1 ms
4,372 KB
testcase_22 AC 1 ms
4,372 KB
testcase_23 AC 1 ms
4,372 KB
testcase_24 AC 1 ms
4,372 KB
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 2 ms
4,372 KB
testcase_27 AC 2 ms
4,372 KB
testcase_28 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

template <typename T,typename E>
class LazySegmentTree{
private:
    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;
    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));
    }
public:
    LazySegmentTree(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]);
    }
    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 operator[](const int k){return query(k,k+1);}
};

struct hoge{
  ll val;
  ll l,r;
  hoge(){}
  hoge(ll val,ll l,ll r):val(val),l(l),r(r){}
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  vll A(N);
  for(ll i=0;i<N;i++){
    cin>>A[i];
  }
  LazySegmentTree<ll,ll> seg([](ll a,ll b){return min(a,b);},[](ll a,ll b){return b<0?a:b;},[](ll a,ll b){return b<0?a:b;},INF,-1);
  seg.build(A);
  vll V(A);
  sort(V.begin(),V.end());
  V.erase(unique(V.begin(),V.end()),V.end());
  map<ll,ll> mp;
  for(ll i=0;i<(ll)V.size();i++){
    mp[V[i]]=i;
  }
  vector<pair<ll,Pll> > query(V.size(),{-1,{-1,-1}});
  for(ll i=0;i<N;i++){
    ll idx=mp[A[i]];
    if(query[idx].first<0){
      query[idx].first=A[i];
      query[idx].second.first=i;
    }
    query[idx].second.second=i;
  }
  for(auto q:query){
    if(q.first<0)continue;
    seg.update(q.second.first,q.second.second+1,q.first);
    //cerr<<q.second.first<<q.second.second<<q.first<<endl;
  }
  for(ll i=0;i<N;i++){
    cout<<seg[i]<<(i<N-1? " ":"\n");
  }
  return 0;
}
0