結果

問題 No.318 学学学学学
ユーザー nxterunxteru
提出日時 2018-07-27 21:45:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 2,695 ms
コンパイル使用メモリ 86,616 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2023-09-04 21:08:10
合計ジャッジ時間 6,107 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,384 KB
testcase_01 AC 16 ms
4,608 KB
testcase_02 AC 20 ms
4,900 KB
testcase_03 AC 13 ms
4,484 KB
testcase_04 AC 17 ms
4,644 KB
testcase_05 AC 114 ms
10,112 KB
testcase_06 AC 88 ms
7,760 KB
testcase_07 AC 76 ms
6,788 KB
testcase_08 AC 63 ms
6,328 KB
testcase_09 AC 53 ms
5,668 KB
testcase_10 AC 41 ms
4,704 KB
testcase_11 AC 113 ms
10,076 KB
testcase_12 AC 75 ms
7,616 KB
testcase_13 AC 64 ms
6,764 KB
testcase_14 AC 54 ms
6,072 KB
testcase_15 AC 45 ms
5,776 KB
testcase_16 AC 32 ms
5,328 KB
testcase_17 AC 64 ms
7,672 KB
testcase_18 AC 55 ms
7,748 KB
testcase_19 AC 64 ms
7,684 KB
testcase_20 AC 32 ms
5,256 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;
int seg[1<<18],n;
void up(int a,int b,int r,int l,int k,int x){
    if(b<r||l<a)return;
    if(a<=r&&l<=b)seg[k]=max(seg[k],x);
    else{
        up(a,b,r,(r+l-1)/2,k*2+1,x);
        up(a,b,(r+l+1)/2,l,k*2+2,x);
    }
}
vector<int>com;
map<int,int>p;
int s[100005],t[100005],q[100005];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        s[i]=100000;
        scanf("%d",q+i);
        com.push_back(q[i]);
    }
    sort(com.begin(),com.end());
    com.erase(unique(com.begin(),com.end()),com.end());
    for(int i=0;i<com.size();i++)p[com[i]]=i;
    for(int i=0;i<n;i++){
        q[i]=p[q[i]];
        s[q[i]]=min(s[q[i]],i);
        t[q[i]]=max(t[q[i]],i);
    }
    for(int i=0;i<com.size();i++){
        up(s[i],t[i],0,(1<<17)-1,0,i);
    }
    for(int i=0;i<n;i++){
        int j=i+(1<<17)-1,ans=seg[j];
        while(j>0){
            j=(j-1)/2;
            ans=max(ans,seg[j]);
        }
        printf("%d",com[ans]);
        if(i!=n-1)printf(" ");
    }
    printf("\n");
}
0