結果

問題 No.318 学学学学学
ユーザー pekempeypekempey
提出日時 2015-12-11 00:24:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 1,287 bytes
コンパイル時間 2,661 ms
コンパイル使用メモリ 163,428 KB
実行使用メモリ 147,216 KB
最終ジャッジ日時 2023-09-04 16:40:24
合計ジャッジ時間 7,007 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
15,388 KB
testcase_01 AC 46 ms
27,996 KB
testcase_02 AC 57 ms
32,920 KB
testcase_03 AC 34 ms
23,180 KB
testcase_04 AC 48 ms
29,268 KB
testcase_05 AC 285 ms
147,188 KB
testcase_06 AC 256 ms
143,864 KB
testcase_07 AC 229 ms
142,108 KB
testcase_08 AC 192 ms
140,820 KB
testcase_09 AC 172 ms
139,164 KB
testcase_10 AC 151 ms
138,132 KB
testcase_11 AC 280 ms
147,216 KB
testcase_12 AC 216 ms
142,596 KB
testcase_13 AC 193 ms
141,124 KB
testcase_14 AC 175 ms
139,896 KB
testcase_15 AC 159 ms
138,804 KB
testcase_16 AC 142 ms
137,892 KB
testcase_17 AC 188 ms
145,036 KB
testcase_18 AC 171 ms
142,572 KB
testcase_19 AC 190 ms
145,072 KB
testcase_20 AC 138 ms
137,916 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using namespace std;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep (i, n) scanf("%d", &a[i]);
	map<int, int> first, last;
	repr (i, n) first[a[i]] = i;
	rep (i, n) last[a[i]] = i;
	vector<stack<int>> start(n), end(n);
	for (auto kv : first) if (last.count(kv.first)) {
		start[kv.second].push(kv.first);
		end[last[kv.first]].push(kv.first);
	}

	set<int> st;
	rep (i, n) {
		while (!start[i].empty()) {
			int top = start[i].top(); start[i].pop();
			st.insert(-top);
		}
		if (!st.empty()) {
			a[i] = -*st.begin();
		}
		while (!end[i].empty()) {
			int top = end[i].top(); end[i].pop();
			st.erase(-top);
		}
	}

	rep (i, n) printf("%d ", a[i]);
	cout << endl;
	return 0;
}
0