結果

問題 No.318 学学学学学
ユーザー h_noson
提出日時 2016-05-30 01:06:52
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,175 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 72,308 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-10-07 17:54:24
合計ジャッジ時間 3,252 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
main.cpp:23:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |         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];

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 s, e;
        s = it->second.first; e = it->second.second;
        while ((s = nxt[s]) < e)
            a[s] = it->first;
        s = prv[it->second.first];
        e = nxt[it->second.second == 0 ? it->second.first : it->second.second];
        int p = s;
        while ((p = nxt[p]) < e) {
            nxt[prv[p]] = e;
            prv[p] = s;
        }
    }
    REP (i,1,n) printf("%d%c",a[i],i < n ? ' ' : '\n');
    return 0;
}
0