結果

問題 No.318 学学学学学
ユーザー krotonkroton
提出日時 2015-12-11 00:06:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 612 bytes
コンパイル時間 1,028 ms
コンパイル使用メモリ 75,976 KB
実行使用メモリ 9,672 KB
最終ジャッジ日時 2023-09-04 16:00:27
合計ジャッジ時間 4,316 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
4,384 KB
testcase_01 AC 19 ms
4,380 KB
testcase_02 AC 23 ms
4,480 KB
testcase_03 AC 15 ms
4,380 KB
testcase_04 AC 21 ms
4,380 KB
testcase_05 AC 156 ms
9,672 KB
testcase_06 AC 126 ms
8,292 KB
testcase_07 AC 109 ms
6,424 KB
testcase_08 AC 94 ms
5,660 KB
testcase_09 AC 82 ms
4,448 KB
testcase_10 AC 65 ms
4,384 KB
testcase_11 AC 154 ms
9,616 KB
testcase_12 AC 101 ms
6,116 KB
testcase_13 AC 85 ms
4,896 KB
testcase_14 AC 74 ms
4,392 KB
testcase_15 AC 64 ms
4,380 KB
testcase_16 AC 52 ms
4,384 KB
testcase_17 AC 87 ms
8,012 KB
testcase_18 AC 65 ms
5,668 KB
testcase_19 AC 83 ms
8,008 KB
testcase_20 AC 37 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin >> a[i];

  map<int, int> R;
  for(int i=n-1;i>=0;i--){
    if(!R.count(a[i])){
      R[a[i]] = i;
    }
  }
  set<int, greater<int>> stk;
  for(int i=0;i<n;i++){
    if(!stk.count(a[i])){
      stk.insert(a[i]);
    }
    while(!stk.empty() && R[*stk.begin()] <= i){
      stk.erase(stk.begin());
    }
    if(!stk.empty() && *stk.begin() > a[i]){
      a[i] = *stk.begin();
    }
  }
  for(int x : a){
    cout << x << " ";
  }
  return 0;
}
0