結果
| 問題 |
No.318 学学学学学
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-22 05:55:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 406 ms / 2,000 ms |
| コード長 | 698 bytes |
| コンパイル時間 | 1,803 ms |
| コンパイル使用メモリ | 201,004 KB |
| 最終ジャッジ日時 | 2025-02-08 11:00:23 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
int n; cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
vector<int> ans(n);
multiset<int> L, R(a.begin(), a.end()), st;
rep(i,n) {
R.erase(R.lower_bound(a[i]));
if(L.count(a[i]) && !R.count(a[i])) st.erase(st.lower_bound(a[i]));
ans[i] = a[i];
if(!st.empty()) ans[i] = max(ans[i], *st.rbegin());
if(!L.count(a[i]) && R.count(a[i])) st.insert(a[i]);
L.insert(a[i]);
}
rep(i,n) cout << ans[i] << " \n"[i == n - 1];
}