結果

問題 No.318 学学学学学
ユーザー tnakao0123tnakao0123
提出日時 2016-04-04 10:33:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 2,371 bytes
コンパイル時間 3,127 ms
コンパイル使用メモリ 93,724 KB
実行使用メモリ 10,772 KB
最終ジャッジ日時 2023-09-04 20:00:10
合計ジャッジ時間 6,132 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,756 KB
testcase_01 AC 21 ms
6,236 KB
testcase_02 AC 25 ms
6,448 KB
testcase_03 AC 17 ms
6,052 KB
testcase_04 AC 22 ms
6,296 KB
testcase_05 AC 140 ms
10,772 KB
testcase_06 AC 112 ms
8,572 KB
testcase_07 AC 97 ms
7,656 KB
testcase_08 AC 85 ms
6,992 KB
testcase_09 AC 76 ms
6,568 KB
testcase_10 AC 62 ms
6,308 KB
testcase_11 AC 137 ms
10,752 KB
testcase_12 AC 99 ms
8,408 KB
testcase_13 AC 86 ms
7,632 KB
testcase_14 AC 75 ms
7,008 KB
testcase_15 AC 65 ms
6,540 KB
testcase_16 AC 52 ms
6,100 KB
testcase_17 AC 77 ms
8,408 KB
testcase_18 AC 68 ms
8,496 KB
testcase_19 AC 79 ms
8,488 KB
testcase_20 AC 38 ms
6,128 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 3 ms
5,316 KB
testcase_23 AC 3 ms
5,448 KB
testcase_24 AC 3 ms
5,388 KB
testcase_25 AC 3 ms
5,292 KB
testcase_26 AC 3 ms
5,356 KB
testcase_27 AC 3 ms
5,420 KB
testcase_28 AC 3 ms
5,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 318.cc: No.318 学学学学学 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_E2 = 1 << 18;

/* typedef */

typedef map<int,int> mii;

template <typename T, const int MAX_E2>
struct SegTreeDelay {
  int n, e2;
  T nodes[MAX_E2];

  SegTreeDelay() {}

  void init(int _n) {
    n = _n;
    for (e2 = 1; e2 < n; e2 <<= 1);
    memset(nodes, 0, sizeof(nodes));
  }

  T get(int i) { return nodes[e2 - 1 + i]; }
  void set(int i, T v) { nodes[e2 - 1 + i] = v; }

  void propagate() {
    for (int j = 0; j < e2 - 1; j++)
      if (nodes[j]) {
	nodes[j * 2 + 1] = nodes[j * 2 + 2] = nodes[j];
	nodes[j] = 0;
      }
  }

  void set_range(T v, int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return;
    if (r0 <= i0 && i1 <= r1) {
      nodes[k] = v;
      return;
    }

    int k0 = k * 2 + 1, k1 = k0 + 1;
    if (nodes[k]) {
      nodes[k0] = nodes[k1] = nodes[k];
      nodes[k] = 0;
    }
    
    int im = (i0 + i1) / 2;
    set_range(v, r0, r1, k0, i0, im);
    set_range(v, r0, r1, k1, im, i1);
  }

  void set_range(T v, int r0, int r1) {
    set_range(v, r0, r1, 0, 0, e2);
  }
};

/* global variables */

int as[MAX_N], gs[MAX_N], mings[MAX_N], maxgs[MAX_N];
mii gmap;
SegTreeDelay<int,MAX_E2> st;

/* subroutines */

/* main */

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> as[i];
    gs[i] = as[i];
  }
  sort(gs, gs + n);
  int gn = unique(gs, gs + n) - gs;
  //printf("gn=%d\n", gn);

  for (int i = 0; i < gn; i++) gmap[gs[i]] = i;

  memset(mings, -1, sizeof(mings));
  memset(maxgs, -1, sizeof(maxgs));

  st.init(n);
  for (int i = 0; i < n; i++) {
    int gi = gmap[as[i]];
    st.set(i, gi);
    if (mings[gi] < 0 || mings[gi] > i) mings[gi] = i;
    if (maxgs[gi] < i) maxgs[gi] = i;
  }

  for (int i = 0; i < gn; i++)
    st.set_range(i, mings[i], maxgs[i] + 1);
  st.propagate();

  for (int i = 0; i < n; i++) {
    if (i) putchar(' ');
    printf("%d", gs[st.get(i)]);
  }
  putchar('\n');
  return 0;
}
0