結果

問題 No.318 学学学学学
ユーザー akakimidoriakakimidori
提出日時 2019-05-26 20:24:41
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,981 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 32,028 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 18:03:28
合計ジャッジ時間 4,014 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,348 KB
testcase_01 AC 8 ms
4,348 KB
testcase_02 AC 10 ms
4,348 KB
testcase_03 AC 7 ms
4,348 KB
testcase_04 AC 8 ms
4,348 KB
testcase_05 AC 47 ms
4,348 KB
testcase_06 AC 50 ms
4,348 KB
testcase_07 AC 45 ms
4,348 KB
testcase_08 AC 42 ms
4,348 KB
testcase_09 AC 39 ms
4,348 KB
testcase_10 AC 36 ms
4,348 KB
testcase_11 AC 46 ms
4,348 KB
testcase_12 AC 42 ms
4,348 KB
testcase_13 AC 40 ms
4,348 KB
testcase_14 AC 39 ms
4,348 KB
testcase_15 AC 36 ms
4,348 KB
testcase_16 AC 32 ms
4,348 KB
testcase_17 AC 34 ms
4,348 KB
testcase_18 AC 31 ms
4,348 KB
testcase_19 AC 31 ms
4,348 KB
testcase_20 AC 30 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

typedef i32 RUQ_val;

typedef struct range_update_query {
  RUQ_val *val;
  int32_t size;
  int32_t bit;
  RUQ_val empty;
} RUQ;

RUQ* new_RUQ (const int32_t n) {
  int32_t k = 0;
  while ((1 << k) < n) ++k;
  RUQ *s = (RUQ *) calloc (1, sizeof (RUQ));
  s->val = (RUQ_val *) calloc (2 << k, sizeof (RUQ_val));
  s->size = 1 << k;
  s->bit = k;
  s->empty = -1;
  return s;
}

static inline void propagate (RUQ *s, int32_t k) {
  if (s->val[k] == s->empty) return;
  s->val[2 * k] = s->val[2 * k + 1] = s->val[k];
  s->val[k] = s->empty;
}

void update (RUQ *s, int32_t l, int32_t r, RUQ_val v) {
  for (int32_t i = s->bit; i > 0; --i) {
    propagate (s, (l + s->size) >> i);
    propagate (s, (r - 1 + s->size) >> i);
  }
  for (l += s->size, r += s->size; l < r; l >>= 1, r >>= 1) {
    if (l & 1) s->val[l++] = v;
    if (r & 1) s->val[--r] = v;
  }
}

RUQ_val find (RUQ *s, int32_t x) {
  x += s->size;
  for (int32_t i = s->bit; i >= 0; --i) {
    if (s->val[x >> i] != s->empty) {
      return s->val[x >> i];
    }
  }
  return s->empty;
}

typedef struct node {
  i32 v;
  i32 k;
} node;

int cmp_node (const void *a, const void *b) {
  i32 d = ((node *)a)->v - ((node *)b)->v;
  if (d != 0) return d < 0 ? -1 : 1;
  d = ((node *)a)->k - ((node *)b)->k;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  node *p = (node *) calloc (n, sizeof (node));
  for (i32 i = 0; i < n; ++i) {
    i32 a;
    scanf ("%" SCNi32, &a);
    p[i] = (node) {a, i};
  }
  qsort (p, n, sizeof (node), cmp_node);
  RUQ *s = new_RUQ (n);
  for (i32 i = 0; i < n;) {
    i32 j = i + 1;
    while (j < n && p[i].v == p[j].v) ++j;
    update (s, p[i].k, p[j - 1].k + 1, p[i].v);
    i = j;
  }
  for (i32 i = 0; i < n; ++i) {
    printf ("%" PRIi32, find (s, i));
    putchar (i == n - 1 ? '\n' : ' ');
  }
}

int main (void) {
  run();
  return 0;
}
0