結果

問題 No.318 学学学学学
ユーザー rogi52rogi52
提出日時 2022-10-22 05:46:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 780 bytes
コンパイル時間 2,641 ms
コンパイル使用メモリ 206,504 KB
実行使用メモリ 8,800 KB
最終ジャッジ日時 2023-09-14 03:26:44
合計ジャッジ時間 7,034 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,380 KB
testcase_01 AC 12 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 10 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 98 ms
8,620 KB
testcase_08 AC 100 ms
8,508 KB
testcase_09 AC 106 ms
8,612 KB
testcase_10 AC 173 ms
8,584 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 57 ms
8,608 KB
testcase_18 AC 55 ms
8,560 KB
testcase_19 AC 66 ms
8,544 KB
testcase_20 WA -
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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];

    multiset<int> L, R(a.begin(), a.end());
    vector<int> ans(n);
    rep(i,n) {
        R.erase(R.lower_bound(a[i]));
        int x = a[i];
        if(!L.empty()) {
            auto itL = L.end(); itL--;
            if(R.count(*itL)) x = max(x, *itL);
        }
        if(!R.empty()) {
            auto itR = R.end(); itR--;
            if(L.count(*itR)) x = max(x, *itR);
        }
        ans[i] = (x == -1 ? a[i] : x);

        L.insert(a[i]);
    }

    rep(i,n) cout << ans[i] << " \n"[i == n - 1];
}
0