結果

問題 No.318 学学学学学
ユーザー chocoruskchocorusk
提出日時 2018-11-15 11:44:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 1,746 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 97,964 KB
実行使用メモリ 15,024 KB
最終ジャッジ日時 2023-09-04 21:17:18
合計ジャッジ時間 6,550 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
4,380 KB
testcase_01 AC 30 ms
5,520 KB
testcase_02 AC 37 ms
5,964 KB
testcase_03 AC 23 ms
4,940 KB
testcase_04 AC 31 ms
5,560 KB
testcase_05 AC 227 ms
14,792 KB
testcase_06 AC 202 ms
10,052 KB
testcase_07 AC 174 ms
8,676 KB
testcase_08 AC 155 ms
7,292 KB
testcase_09 AC 132 ms
6,604 KB
testcase_10 AC 105 ms
5,756 KB
testcase_11 AC 233 ms
15,024 KB
testcase_12 AC 170 ms
10,136 KB
testcase_13 AC 143 ms
8,560 KB
testcase_14 AC 116 ms
7,332 KB
testcase_15 AC 93 ms
6,592 KB
testcase_16 AC 73 ms
5,640 KB
testcase_17 AC 138 ms
10,284 KB
testcase_18 AC 115 ms
10,236 KB
testcase_19 AC 136 ms
10,068 KB
testcase_20 AC 56 ms
5,540 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MAX_N=1<<17;
int ans[2*MAX_N-1], part[2*MAX_N-1];
int m;
void init(int n){
    m=1;
    while(m<n) m*=2;
    for(int i=0; i<2*m-1; i++){
        ans[i]=0;
        part[i]=0;
    }
}
  
void eval(int k, int l, int r){
    if(part[k]>0){
        ans[k]=part[k];
        if(k<m-1){
            part[2*k+1]=part[k];
            part[2*k+2]=part[k];
        }
        part[k]=0;
    }
}
    
void update(int a, int b, int x, int k, int l, int r){
  eval(k, l, r);
  if(r<=a || b<=l) return;
    if(a<=l && r<=b){
        part[k]=x;
        eval(k, l, r);
    }else{
        update(a, b, x, k*2+1, l, (l+r)/2);
        update(a, b, x, k*2+2, (l+r)/2, r);
        ans[k]=max(ans[2*k+1], ans[2*k+2]);
    }
}
    
int find(int a, int b, int k, int l, int r){
  eval(k, l, r);
    if(b<=l || r<=a){
        return 0;
    }
    if(a<=l && r<=b){
        return ans[k];
    }else{
        return max(find(a, b, 2*k+1, l, (l+r)/2), find(a, b, 2*k+2, (l+r)/2, r));
    }
}
int main()
{
	int n;
	cin>>n;
	map<int, int> mn, mx;
	for(int i=0; i<n; i++){
		int a;
		cin>>a;
		if(mn.find(a)==mn.end()){
			mn[a]=i;
			mx[a]=i;
		}else{
			mn[a]=min(i, mn[a]);
			mx[a]=max(i, mx[a]);
		}
	}
	init(n);
	for(auto p:mn){
		int a=p.first, i1=p.second, i2=mx[a];
		update(i1, i2+1, a, 0, 0, m);
	}
	for(int i=0; i<n; i++){
		cout<<find(i, i+1, 0, 0, m);
		if(i<n-1) cout<<" ";
	}
	cout<<endl;
	return 0;
}
0