結果

問題 No.318 学学学学学
ユーザー NrKmDevNrKmDev
提出日時 2020-07-08 17:24:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 2,390 bytes
コンパイル時間 1,973 ms
コンパイル使用メモリ 176,084 KB
実行使用メモリ 15,692 KB
最終ジャッジ日時 2024-04-15 00:10:45
合計ジャッジ時間 6,730 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
6,816 KB
testcase_01 AC 30 ms
6,944 KB
testcase_02 AC 37 ms
6,944 KB
testcase_03 AC 24 ms
6,944 KB
testcase_04 AC 31 ms
6,940 KB
testcase_05 AC 203 ms
15,692 KB
testcase_06 AC 175 ms
12,564 KB
testcase_07 AC 151 ms
11,400 KB
testcase_08 AC 130 ms
10,572 KB
testcase_09 AC 118 ms
9,936 KB
testcase_10 AC 100 ms
9,512 KB
testcase_11 AC 198 ms
15,564 KB
testcase_12 AC 147 ms
12,440 KB
testcase_13 AC 131 ms
11,396 KB
testcase_14 AC 116 ms
10,568 KB
testcase_15 AC 104 ms
9,940 KB
testcase_16 AC 88 ms
9,508 KB
testcase_17 AC 136 ms
12,440 KB
testcase_18 AC 117 ms
12,380 KB
testcase_19 AC 131 ms
12,564 KB
testcase_20 AC 69 ms
9,404 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
typedef vector<string> vs;
typedef pair<l_l,ll> lll;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
template<class T> inline bool chmin(T& a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
ll n,N;
vl a,node,lazy;
void init(){
    N=1;
    while(N<n)N*=2;
    node.resize(2*N-1,0);
    lazy.resize(2*N-1,0);
}
void eval(ll l,ll r,ll pos){
    if(lazy[pos]!=0){
        node[pos]=max(node[pos],lazy[pos]);
        if(r-l>1){
            lazy[2*pos+1]=lazy[pos];
            lazy[2*pos+2]=lazy[pos];
        }
        lazy[pos]=0;
    }
}
void add(ll l,ll r,ll val,ll bottom=0,ll top=-1,ll pos=0){
    if(top<0)top=N;
    //cout<<pos<<endl;
    eval(bottom,top,pos);
    if(r<=bottom||top<=l)return;
    if(l<=bottom&&top<=r){
        lazy[pos]=max(val,lazy[pos]);
        eval(bottom,top,pos);
    }else{
        ll mid=(bottom+top)/2;
        add(l,r,val,bottom,mid,2*pos+1);
        add(l,r,val,mid,top,2*pos+2);
        node[pos]=max(node[2*pos+1],node[2*pos+2]);
    }
}
ll getmax(ll l,ll r,ll bottom=0,ll top=-1,ll pos=0){
    if(top<0)top=N;
    eval(bottom,top,pos);
    if(r<=bottom||top<=l)return 0;
    if(l<=bottom&&top<=r)return node[pos];
    ll mid=(bottom+top)/2;
    ll vl=getmax(l,r,bottom,mid,2*pos+1);
    ll vr=getmax(l,r,mid,top,2*pos+2);
    return max(vl,vr);
}
int main(){
    cin>>n;
    init();
    a.resize(n,0);
    rep(i,n)cin>>a[i];
    map<ll,l_l> mp;
    rep(i,n){
        if(mp[a[i]].fi==0&&mp[a[i]].se==0){
            //cout<<a[i]<<" "<<i<<endl;
            mp[a[i]]={i+1,i+1};
        }else{
            mp[a[i]].se=i+1;
        }
    }
    for(auto p:mp){
        //cout<<p.fi<<" "<<p.se.fi<<" "<<p.se.se<<endl;
        add(p.se.fi-1,p.se.se,p.fi);
    }
    vl b;
    rep(i,n)b.pb(getmax(i,i+1));
    for(auto bb:b)cout<<bb<<" ";
    cout<<endl;
    return 0;
}
0