結果

問題 No.318 学学学学学
ユーザー h_nosonh_noson
提出日時 2016-05-30 01:45:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,378 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 72,152 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-16 18:24:13
合計ジャッジ時間 3,500 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,248 KB
testcase_01 AC 14 ms
5,376 KB
testcase_02 AC 16 ms
5,376 KB
testcase_03 AC 11 ms
5,376 KB
testcase_04 AC 14 ms
5,376 KB
testcase_05 AC 106 ms
11,136 KB
testcase_06 AC 79 ms
7,936 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 53 ms
5,504 KB
testcase_10 AC 41 ms
5,376 KB
testcase_11 AC 102 ms
11,136 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 30 ms
5,376 KB
testcase_17 AC 56 ms
8,064 KB
testcase_18 AC 52 ms
7,936 KB
testcase_19 AC 55 ms
7,936 KB
testcase_20 WA -
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |         scanf("%d",a+i);
      |         ~~~~~^~~~~~~~~~

ソースコード

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;
        used[p] = true;
        while ((p = nxt[p]) < right) if (!used[p]) {
            a[p] = it->first;
            used[p] = true;
        }
        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