結果

問題 No.318 学学学学学
ユーザー ふーらくたる
提出日時 2018-01-09 00:25:25
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 828 ms
コンパイル使用メモリ 77,492 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-06-22 18:30:34
合計ジャッジ時間 3,170 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;

#define repeat(i, x) for (int i = 0; (i) < (int)(x); (i)++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> a(N, 0);
    map<int, int> right_end;
    repeat (i, N) {
        cin >> a[i];
        right_end[a[i]] = i;
    }

    set<int> S;
    repeat (i, N) {
        S.insert(a[i]);
        int maxa;
        while (right_end[(maxa = *S.rbegin())] < i) {
            S.erase(maxa);
        }
        cout << maxa << " ";
    }
    cout << endl;

    return 0;
}
0