結果

問題 No.318 学学学学学
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-09-01 22:22:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 1,566 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 161,024 KB
実行使用メモリ 10,436 KB
最終ジャッジ日時 2023-09-04 20:14:15
合計ジャッジ時間 5,846 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,380 KB
testcase_01 AC 17 ms
4,680 KB
testcase_02 AC 21 ms
5,016 KB
testcase_03 AC 14 ms
4,636 KB
testcase_04 AC 18 ms
4,676 KB
testcase_05 AC 117 ms
10,356 KB
testcase_06 AC 122 ms
8,532 KB
testcase_07 AC 104 ms
7,472 KB
testcase_08 AC 89 ms
6,188 KB
testcase_09 AC 77 ms
5,428 KB
testcase_10 AC 64 ms
4,408 KB
testcase_11 AC 118 ms
10,436 KB
testcase_12 AC 90 ms
7,200 KB
testcase_13 AC 80 ms
6,160 KB
testcase_14 AC 71 ms
5,336 KB
testcase_15 AC 63 ms
4,808 KB
testcase_16 AC 52 ms
4,612 KB
testcase_17 AC 83 ms
9,860 KB
testcase_18 AC 66 ms
7,224 KB
testcase_19 AC 85 ms
9,592 KB
testcase_20 AC 35 ms
4,556 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 2 ms
4,384 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        os << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os;
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<int> A;
    void input() {
        cin >> N;
        A.resize(N); cin >> A;
    }

    void dump(set<int>& s) {
        cout << "set: ";
        for (auto e: s) {
            cout << e << " " << endl;
        }
    }

    void solve() {
        map<int, pair<int,int>> m;
        for (int i = 0; i < N; i++) {
            int a = A[i];
            if (not m.count(a)) m[a] = make_pair(i, -1);
            else m[a].second = i;
        }
        vector<int> e(N, 0);
        for (auto it = m.begin(); it != m.end(); it++) {
            if (it->second.second < 0) continue;
            e[it->second.first] = 1;
            e[it->second.second] = -1;
        }
        set<int> s;
        vector<int> B(N, -1);
        for (int i = 0; i < N; i++) {
            if (e[i] == 1) s.insert(A[i]);
            if (s.empty()) B[i] = A[i];
            else {
                int b = max(A[i], *s.rbegin());
                B[i] = b;
            }
            if (e[i] == -1) s.erase(A[i]);
        }
        cout << B << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0