結果

問題 No.318 学学学学学
ユーザー codershifthcodershifth
提出日時 2016-05-07 10:43:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,487 bytes
コンパイル時間 2,926 ms
コンパイル使用メモリ 157,784 KB
実行使用メモリ 10,228 KB
最終ジャッジ日時 2023-09-04 20:05:57
合計ジャッジ時間 5,177 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,376 KB
testcase_01 AC 14 ms
4,580 KB
testcase_02 AC 17 ms
4,656 KB
testcase_03 AC 12 ms
4,428 KB
testcase_04 AC 15 ms
4,696 KB
testcase_05 AC 139 ms
10,172 KB
testcase_06 AC 124 ms
8,096 KB
testcase_07 AC 114 ms
7,028 KB
testcase_08 AC 91 ms
5,976 KB
testcase_09 AC 74 ms
4,880 KB
testcase_10 AC 48 ms
4,380 KB
testcase_11 AC 120 ms
10,228 KB
testcase_12 AC 79 ms
7,044 KB
testcase_13 AC 59 ms
6,020 KB
testcase_14 AC 47 ms
5,136 KB
testcase_15 AC 36 ms
4,380 KB
testcase_16 AC 26 ms
4,384 KB
testcase_17 AC 71 ms
9,372 KB
testcase_18 AC 55 ms
6,956 KB
testcase_19 AC 73 ms
9,404 KB
testcase_20 AC 24 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class GakuX5
{
public:
    void solve(void)
    {
        int n;
        cin>>n;

        //
        // bi が t に置き換えられるのは bi の左右に t が存在するときなので
        // bi = max{t| l<=i<=r && t == a[l] == a[r]}
        //       t
        //
        // 区間を管理するために a[i] が出現する最も右側の indext を登録しておく
        vector<ll> a(n);
        map<ll,int> mostRight;
        REP(i,n)
        {
            cin>>a[i];
            mostRight[a[i]] = i;        // a[i] が出現する最右 index を登録
        }
        set<ll> s;
        // O(n*log(n))
        REP(i,n)
        {
            s.insert(a[i]);
            // bi 出力時に登録されている a[i] は i か、それより左側の a[i]
            cout<<*s.rbegin();  // 登録されているもののうち最大のものを出力

            // 以後右側に a[i] はない
            if (i == mostRight[a[i]])
                s.erase(a[i]);
            if (i != n-1)
                cout<<" ";
        }
        cout<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new GakuX5();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0