結果

問題 No.2210 equence Squence Seuence
ユーザー 👑 chro_96chro_96
提出日時 2023-02-10 22:04:30
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 1,785 bytes
コンパイル時間 1,121 ms
コンパイル使用メモリ 30,384 KB
実行使用メモリ 6,436 KB
最終ジャッジ日時 2023-09-21 23:20:38
合計ジャッジ時間 6,976 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 66 ms
4,428 KB
testcase_04 AC 75 ms
4,596 KB
testcase_05 AC 121 ms
4,840 KB
testcase_06 AC 101 ms
4,612 KB
testcase_07 AC 290 ms
5,852 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 364 ms
6,332 KB
testcase_14 AC 366 ms
6,436 KB
testcase_15 AC 363 ms
6,212 KB
testcase_16 AC 366 ms
6,384 KB
testcase_17 AC 364 ms
6,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 303 ms
5,336 KB
testcase_24 AC 217 ms
5,156 KB
testcase_25 AC 265 ms
5,276 KB
testcase_26 AC 370 ms
5,748 KB
testcase_27 AC 86 ms
4,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int t[524287] = {};
int size = 1;

void set_segt (int *t, int idx, int val, int size) {
  idx = idx+size-1;
  t[idx] = val;
  
  while (idx > 0) {
    idx = (idx-1)/2;
    if (t[2*idx+1] > 0) {
      t[idx] = 1;
    } else if (t[2*idx+1] < 0) {
      t[idx] = -1;
    } else {
      t[idx] = t[2*idx+2];
    }
  }
  
  return;
}

int add_segt_rec (int *t, int a, int b, int k, int l, int r) {
  int ans = 0;
  
  if (r <= a || b <= l) {
    return 0;
  }
  
  if (a <= l && r <= b) {
    return t[k];
  }
  
  ans = add_segt_rec(t, a, b, 2*k+1, l, (l+r)/2);
  if (ans == 0) {
    ans = add_segt_rec(t, a, b, 2*k+2, (l+r)/2, r);
  }
  
  return ans;
}

int add_segt (int *t, int a, int b, int size) {
  return add_segt_rec(t, a, b, 0, 0, size);
}

int cmp_idx (const void *ap, const void *bp) {
  int a = *(int *)ap;
  int b = *(int *)bp;
  if (a == b) {
    return 0;
  }
  if (a > b) {
    return (-1)*cmp_idx(bp, ap);
  }  
  return add_segt(t, a, b, size);
}

int main () {
  int n = 0;
  int k = 0;
  int a[200000] = {};
  
  int res = 0;
  
  int ans[200000] = {};
  int b[200000] = {};
  
  res = scanf("%d", &n);
  res = scanf("%d", &k);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", a+i);
    ans[i] = i;
  }
  
  while (size < n) {
    size <<= 1;
  }
  
  for (int i = 0; i < n-1; i++) {
    int val = 0;
    if (a[i] < a[i+1]) {
      val = 1;
    } else if (a[i] > a[i+1]) {
      val = -1;
    }
    set_segt(t, i, val, size);
  }
  
  qsort(ans, n, sizeof(int), cmp_idx);
  
  for (int i = 0; i < ans[k-1]; i++) {
    b[i] = a[i];
  }
  for (int i = ans[k-1]; i < n-1; i++) {
    b[i] = a[i+1];
  }
  
  
  printf("%d", b[0]);
  for (int i = 1; i < n-1; i++) {
    printf(" %d", b[i]);
  }
  printf("\n");
  
  return 0;
}
0