結果

問題 No.318 学学学学学
ユーザー koba-e964koba-e964
提出日時 2016-12-06 18:11:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 1,527 bytes
コンパイル時間 2,511 ms
コンパイル使用メモリ 95,200 KB
実行使用メモリ 18,540 KB
最終ジャッジ日時 2023-09-04 20:35:54
合計ジャッジ時間 5,776 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,592 KB
testcase_01 AC 29 ms
5,960 KB
testcase_02 AC 36 ms
6,360 KB
testcase_03 AC 23 ms
5,324 KB
testcase_04 AC 32 ms
6,208 KB
testcase_05 AC 219 ms
18,540 KB
testcase_06 AC 188 ms
12,460 KB
testcase_07 AC 150 ms
10,076 KB
testcase_08 AC 115 ms
8,032 KB
testcase_09 AC 92 ms
5,900 KB
testcase_10 AC 68 ms
4,396 KB
testcase_11 AC 226 ms
18,372 KB
testcase_12 AC 134 ms
11,328 KB
testcase_13 AC 108 ms
9,004 KB
testcase_14 AC 86 ms
7,060 KB
testcase_15 AC 70 ms
5,692 KB
testcase_16 AC 53 ms
4,384 KB
testcase_17 AC 107 ms
13,392 KB
testcase_18 AC 93 ms
11,652 KB
testcase_19 AC 106 ms
13,796 KB
testcase_20 AC 38 ms
4,612 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 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,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;



int main(void){
  int n;
  cin >> n;
  VL a(n);
  set<ll> a_s;
  REP(i, 0, n) {
    cin >> a[i];
    a_s.insert(a[i]);
  }
  VL comp(a_s.begin(), a_s.end());
  map<ll, int> inv_comp;
  int m = comp.size();
  REP(i, 0, m) {
    inv_comp[comp[i]] = i;
  }
  vector<PI> range(m, PI(n, 0));
  REP(i, 0, n) {
    ll v = a[i];
    int idx = inv_comp[v];
    range[idx].first = min(range[idx].first, i);
    range[idx].second = max(range[idx].second, i);
  }
  vector<PI> actions;
  REP(i, 0, m) {
    actions.push_back(PI(range[i].first, 2 * i + 0));
    actions.push_back(PI(range[i].second, 2 * i + 1));
  }
  sort(actions.begin(), actions.end());
  VI result(n);
  set<int> active;
  int cur = -1;
  REP(i, 0, 2 * m) {
    PI cur2 = actions[i];
    int t = cur2.first;
    int idx = cur2.second / 2;
    if (active.size() > 0) {
      int midx = *active.rbegin();
      while (cur < t) {
	cur++;
	result[cur] = comp[midx];
      }
    }
    if (cur2.second % 2 == 0) {
      active.insert(idx);
      int midx = *active.rbegin();
      result[t] = comp[midx];
    }
    if (cur2.second % 2 == 1) {
      assert (active.count(idx));
      active.erase(idx);
    }
  }
  REP(i, 0, n) {
    cout << result[i] << (i == n - 1 ? "\n" : " ");
  }
}
0