結果

問題 No.318 学学学学学
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-09-01 21:40:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,555 bytes
コンパイル時間 1,545 ms
コンパイル使用メモリ 175,640 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-27 14:28:03
合計ジャッジ時間 5,509 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
6,812 KB
testcase_01 AC 18 ms
6,944 KB
testcase_02 WA -
testcase_03 AC 14 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 115 ms
8,704 KB
testcase_07 AC 103 ms
7,680 KB
testcase_08 AC 90 ms
6,944 KB
testcase_09 AC 77 ms
6,940 KB
testcase_10 AC 67 ms
6,944 KB
testcase_11 WA -
testcase_12 AC 88 ms
7,552 KB
testcase_13 AC 80 ms
6,944 KB
testcase_14 AC 69 ms
6,944 KB
testcase_15 AC 64 ms
6,944 KB
testcase_16 AC 53 ms
6,944 KB
testcase_17 AC 84 ms
9,856 KB
testcase_18 AC 69 ms
7,680 KB
testcase_19 AC 84 ms
9,856 KB
testcase_20 AC 36 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = *s.rbegin();
                B[i] = b;
            }
            if (e[i] == -1) s.erase(A[i]);
        }
        cout << B << endl;
    }
}

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

0