結果

問題 No.318 学学学学学
ユーザー SugarDragon5SugarDragon5
提出日時 2018-08-09 22:05:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 4,050 bytes
コンパイル時間 2,104 ms
コンパイル使用メモリ 181,220 KB
実行使用メモリ 11,224 KB
最終ジャッジ日時 2023-09-04 21:13:47
合計ジャッジ時間 6,561 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,376 KB
testcase_01 AC 28 ms
4,568 KB
testcase_02 AC 34 ms
4,780 KB
testcase_03 AC 21 ms
4,380 KB
testcase_04 AC 29 ms
4,624 KB
testcase_05 AC 189 ms
11,224 KB
testcase_06 AC 199 ms
8,340 KB
testcase_07 AC 174 ms
7,172 KB
testcase_08 AC 151 ms
6,560 KB
testcase_09 AC 130 ms
5,636 KB
testcase_10 AC 105 ms
5,228 KB
testcase_11 AC 193 ms
11,224 KB
testcase_12 AC 152 ms
8,212 KB
testcase_13 AC 131 ms
7,288 KB
testcase_14 AC 112 ms
6,172 KB
testcase_15 AC 97 ms
5,680 KB
testcase_16 AC 82 ms
5,048 KB
testcase_17 AC 152 ms
8,324 KB
testcase_18 AC 128 ms
8,288 KB
testcase_19 AC 149 ms
8,320 KB
testcase_20 AC 66 ms
5,108 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
using Pl=pair<ll,ll>;
using PPl=pair<ll,Pl>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
template<typename Monoid,typename OperatorMonoid=Monoid>
struct LazySegTree{
    //0-indexed 閉区間
    using F=function<Monoid(Monoid,Monoid)>;
    using G=function<Monoid(Monoid,OperatorMonoid)>;
    using H=function<OperatorMonoid(OperatorMonoid,OperatorMonoid)>;
    using P=function<OperatorMonoid(OperatorMonoid,int)>;

    int size;
    vector<Monoid> data;
    vector<OperatorMonoid> lazy;
    const F f;  //要素同士の演算
    const G g;  //要素と作用素のマージ
    const H h;  //作用素同士のマージ
    const P p;  //作用素を下に降ろす
    const Monoid M1;    //単位元
    const OperatorMonoid OM0;   //作用素の単位元

    LazySegTree(int n,const F f,const G g,const H h,const P p,const Monoid &M1,const OperatorMonoid OM0)
        :f(f),g(g),h(h),p(p),M1(M1),OM0(OM0){
        size=1;
        while(size<n)size<<=1;
        data.assign(size*2-1,M1);
        lazy.assign(size*2-1,OM0);
    }

    void set(int k,const Monoid &x){
        //kをxに初期化
        //buildを忘れずに行うこと
        data[k+size-1]=x;
    }
    void build(){
        //構築 O(N)
        for(int k=size-2;k>=0;k--){
            data[k]=f(data[2*k+1],data[2*k+2]);
        }
    }
    void propagate(int k,int len){
        //長さlenのkから下へ伝播
        if(lazy[k]!=OM0){
            if(k<size-1){
                lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
                lazy[2*k+2]=h(lazy[2*k+2],lazy[k]);
            }
            data[k]=g(data[k],p(lazy[k],len));
            lazy[k]=OM0;
        }
    }

    Monoid update(int a,int b,const OperatorMonoid &x,int k,int l,int r){
        propagate(k,r-l+1);
        if(r<a||b<l){ //範囲外
            return data[k];
        }else if(a<=l&&b>=r){   //内部
            lazy[k]=h(lazy[k],x);
            propagate(k,r-l+1);
            return data[k];
        }else{
            return data[k]=f(update(a,b,x,2*k+1,l,(l+r)/2),
                    update(a,b,x,2*k+2,(l+r)/2+1,r));
        }
    }
    Monoid update(int a,int b,const OperatorMonoid &x){
        //[a,b]をxに変更
        return update(a,b,x,0,0,size-1);
    }

    Monoid query(int a,int b,int k,int l,int r){
        propagate(k,r-l+1);
        if(r<a||b<l){
            return M1;
        }else if(a<=l&&b>=r){
            return data[k];
        }else{
            return f(query(a,b,2*k+1,l,(l+r)/2),
                    query(a,b,2*k+2,(l+r)/2+1,r));
        }
    }
    Monoid query(int a,int b){
        return query(a,b,0,0,size-1);
    }

    Monoid operator[](const int &k){
        return query(k,k);
    }
    void debug(){
        for(int i=0;i<size;i++){
            if(i)cerr<<" ";cerr<<(*this)[i];
        }cerr<<endl;
    }
};
int main(){
    int n;
    cin>>n;
    map<int,P> ma;
    REP(i,n){
        int t;
        cin>>t;
        if(ma.find(t)==ma.end()){
            ma[t]=P(i,i);
        }else{
            ma[t]=P(min(ma[t].fi,i),max(ma[t].se,i));
        }
    }
    auto f=[](int a,int b){
        return max(a,b);
    };
    auto g=[](int a,int b){
        return b;
    };
    auto p=[](int a,int b){
        return a;
    };
    LazySegTree<int> tr(n,f,g,g,p,0,0);
    for(auto itr:ma){
        tr.update(itr.se.fi,itr.se.se,itr.fi);
    }
    REP(i,n){
        if(i)cout<<" ";cout<<tr[i];
    }cout<<endl;
    return 0;
}
0