結果

問題 No.318 学学学学学
ユーザー h_nosonh_noson
提出日時 2016-05-30 02:24:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,384 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 72,972 KB
実行使用メモリ 11,096 KB
最終ジャッジ日時 2023-09-04 20:13:01
合計ジャッジ時間 3,705 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,376 KB
testcase_01 AC 13 ms
4,900 KB
testcase_02 AC 15 ms
5,044 KB
testcase_03 AC 10 ms
4,528 KB
testcase_04 AC 13 ms
4,856 KB
testcase_05 AC 86 ms
10,996 KB
testcase_06 AC 68 ms
7,856 KB
testcase_07 AC 64 ms
6,820 KB
testcase_08 AC 58 ms
5,996 KB
testcase_09 AC 52 ms
5,424 KB
testcase_10 AC 41 ms
5,052 KB
testcase_11 AC 93 ms
11,096 KB
testcase_12 AC 63 ms
7,856 KB
testcase_13 AC 53 ms
6,880 KB
testcase_14 AC 44 ms
6,244 KB
testcase_15 AC 36 ms
5,428 KB
testcase_16 AC 29 ms
4,864 KB
testcase_17 AC 55 ms
7,852 KB
testcase_18 AC 51 ms
7,868 KB
testcase_19 AC 55 ms
7,928 KB
testcase_20 AC 25 ms
4,956 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)(1e9+7)

typedef long long ll;

int a[100100], nxt[100100], prv[100100];
bool used[100100];

int main(void) {
    int i, n;
    map<int,pair<int,int>> mp;
    scanf("%d",&n);
    REP (i,1,n) {
        scanf("%d",a+i);
        if (!mp.count(a[i]))
            mp[a[i]].first = i;
        else 
            mp[a[i]].second = i;
        nxt[i] = i+1;
        prv[i] = i-1;
    }
    nxt[0] = 1;
    for (auto it = mp.rbegin(); it != mp.rend(); it++) {
        int left, right, p;
        left = it->second.first;
        right = it->second.second == 0 ? it->second.first : it->second.second;
        p = left;
        while (p <= right) {
            if (!used[p])
                a[p] = it->first;
            used[p] = true;
            p = nxt[p];
        }
        p = left;
        while (p <= right) {
            int tmp = nxt[p];
            nxt[p] = nxt[right];
            prv[p] = prv[left];
            p = tmp;
        }
        nxt[prv[left]] = nxt[right];
        prv[nxt[right]] = prv[left];
    }
    REP (i,1,n) printf("%d%c",a[i],i < n ? ' ' : '\n');
    return 0;
}
0