結果

問題 No.318 学学学学学
ユーザー ferinferin
提出日時 2017-08-03 23:13:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 3,187 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 159,004 KB
実行使用メモリ 12,320 KB
最終ジャッジ日時 2023-09-04 20:51:27
合計ジャッジ時間 5,466 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
4,464 KB
testcase_01 AC 18 ms
5,116 KB
testcase_02 AC 22 ms
5,376 KB
testcase_03 AC 15 ms
4,900 KB
testcase_04 AC 19 ms
5,188 KB
testcase_05 AC 107 ms
11,984 KB
testcase_06 AC 102 ms
9,600 KB
testcase_07 AC 88 ms
8,720 KB
testcase_08 AC 78 ms
8,300 KB
testcase_09 AC 70 ms
7,616 KB
testcase_10 AC 61 ms
7,296 KB
testcase_11 AC 106 ms
12,320 KB
testcase_12 AC 85 ms
9,604 KB
testcase_13 AC 76 ms
8,596 KB
testcase_14 AC 70 ms
7,956 KB
testcase_15 AC 66 ms
7,684 KB
testcase_16 AC 58 ms
7,436 KB
testcase_17 AC 71 ms
9,452 KB
testcase_18 AC 61 ms
9,456 KB
testcase_19 AC 70 ms
9,404 KB
testcase_20 AC 43 ms
7,296 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,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

VI aa, a, unzip(100010);
unordered_map<int, int> zip;
int n;
VI compress() {
  a = aa;
  sort(ALL(aa));
  aa.erase(unique(ALL(aa)), aa.end());
  REP(i, aa.size()) {
    zip[aa[i]] = i;
    unzip[i] = aa[i];
  }
  REP(i, a.size()) {
    a[i] = zip[a[i]];
  }
  return a;
}

const int MAX_N = 1<<17;

int dat[MAX_N*2-1], lazy[MAX_N*2-1];
bool flag[MAX_N*2-1];

void init(int n_) {
  n = 1;
  while(n < n_) n *= 2;
  REP(i, n*2-1) {
    dat[i] = INT_MAX;
    lazy[i] = 0;
    flag[i] = false;
  }
}

void eval(int k, int l, int r) {
  if(flag[k]) {
    dat[k] = lazy[k];
    if(r-l>1) {
      lazy[2*k+1] = lazy[k]; flag[2*k+1] = true;
      lazy[2*k+2] = lazy[k]; flag[2*k+2] = true;
    }
    flag[k] = false;
  }
}

void update(int a, int b, ll x, int k=0, int l=0, int r=-1) {
  if(r < 0) r = n;
  // cout << a << " " << b << " " << x << " " << k << " " << l << " " << r << endl;

  eval(k, l, r);

  if(b <= l || r <= a) {
    // cout << "a" << endl;
    return;
  }

  if(a <= l && r <= b) {
    // cout << "b" << endl;
    lazy[k] = x;
    flag[k] = true;
    eval(k, l, r);
  } else {
    // cout << "c" << endl;
    update(a, b, x, 2*k+1, l, (l+r)/2);
    update(a, b, x, 2*k+2, (l+r)/2, r);
    // dat[k] = min(dat[2*k+1], dat[2*k+2]);
  }
}

ll getMin(int a, int b, int k=0, int l=0, int r=-1) {
  if(r < 0) r = n;
  // cout << a << " " << b << " " << k << " " << l << " " << r << endl;

  eval(k, l, r);

  if(b <= l || r <= a) {
    // cout << "a" << endl;
    return INT_MAX;
  }
  if(a <= l && r <= b) {
    // cout << "b" << endl;
    return dat[k];
  }
  // cout << "c" << endl;
  ll vl = getMin(a, b, 2*k+1, l, (l+r)/2);
  ll vr = getMin(a, b, 2*k+2, (l+r)/2, r);
  return min(vl, vr);
}

void f(int k=0, int l=0, int r=n) {
  eval(k, l, r);
  if(r-l == 1) return;
  f(2*k+1, l, (l+r)/2);
  f(2*k+2, (l+r)/2, r);
}

int lr[100010][2];
signed main(void)
{
  int nn;
  cin >> nn;
  REP(i, nn) {
    int x;
    cin >> x;
    aa.PB(x);
    lr[i][0] = -1;
  }
  compress();
  // REP(i, nn) cout << a[i] << " "; cout << endl;
  REP(i, nn) {
    if(lr[a[i]][0] == -1) lr[a[i]][0] = i;
    lr[a[i]][1] = i;
  }

  init(nn);
  REP(i, nn) {
    if(lr[i][0] == -1) continue;
    // cout << lr[i][0] << " " << lr[i][1] << endl;
    // [lr[i][0], lr[i][1]+1) を unzip[i] に変更する
    update(lr[i][0], lr[i][1]+1, unzip[i]);
  }
  f();
  REP(i, nn) {
    cout << dat[i+n-1];
    if(i == nn-1) cout << "\n";
    else cout << " ";
  }

  return 0;
}
0