結果

問題 No.318 学学学学学
ユーザー koyumeishikoyumeishi
提出日時 2015-12-11 00:17:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,259 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 87,576 KB
実行使用メモリ 7,384 KB
最終ジャッジ日時 2023-09-04 16:22:31
合計ジャッジ時間 5,105 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,380 KB
testcase_01 AC 10 ms
4,380 KB
testcase_02 AC 12 ms
4,380 KB
testcase_03 AC 8 ms
4,380 KB
testcase_04 AC 11 ms
4,376 KB
testcase_05 AC 55 ms
5,380 KB
testcase_06 AC 73 ms
6,336 KB
testcase_07 AC 65 ms
5,972 KB
testcase_08 AC 56 ms
5,724 KB
testcase_09 AC 49 ms
5,448 KB
testcase_10 AC 40 ms
4,620 KB
testcase_11 AC 55 ms
5,540 KB
testcase_12 AC 50 ms
4,848 KB
testcase_13 AC 47 ms
4,932 KB
testcase_14 AC 44 ms
4,976 KB
testcase_15 AC 39 ms
4,704 KB
testcase_16 AC 32 ms
4,732 KB
testcase_17 AC 51 ms
7,384 KB
testcase_18 AC 36 ms
5,164 KB
testcase_19 AC 52 ms
7,308 KB
testcase_20 AC 30 ms
4,624 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

vector<int> b;
int sz;
template<class T>
vector<T> compress(vector<T> a){
	b = a;
	sort(b.begin(), b.end());
	b.erase( unique(b.begin(), b.end()), b.end());
	
	sz = b.size();

	for(int i=0; i<a.size(); i++){
		a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
	}
	return a;
}

template<class T>
ostream& operator << (ostream& os, vector<T> vec){
	for(int i=0; i<vec.size(); i++){
		os << vec[i] << " ";
	}
	return os;
}

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		scanf("%d", &a[i]);
	}

	auto c = compress(a);
	vector<int> left(sz, sz);
	vector<int> right(sz, -1);
	for(int i=0; i<n; i++){
		right[c[i]] = i;
	}
	for(int i=n-1; i>=0; i--){
		left[c[i]] = i;
	}

	//cerr << c << endl;
	//cerr << left << endl;
	//cerr << right << endl;

	set<int> unko;
	vector<int> d(n, 0);
	for(int i=0; i<n; i++){
		if(left[c[i]] == i){
			unko.insert(c[i]);
		}
		d[i] = b[*unko.rbegin()];
		if(right[c[i]] == i){
			unko.erase(c[i]);
		}
	}

	for(int i=0; i<n; i++){
		printf("%d%s", d[i], (i==n-1?"\n":" "));
	}


	
	return 0;
}
0