結果

問題 No.2165 Let's Play Nim!
ユーザー 👑 chro_96chro_96
提出日時 2022-12-16 00:44:52
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 2,251 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 30,672 KB
実行使用メモリ 58,316 KB
平均クエリ数 858.54
最終ジャッジ日時 2023-08-09 10:00:27
合計ジャッジ時間 16,036 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
57,972 KB
testcase_01 AC 146 ms
57,976 KB
testcase_02 AC 153 ms
58,128 KB
testcase_03 AC 110 ms
58,092 KB
testcase_04 AC 36 ms
57,680 KB
testcase_05 AC 42 ms
57,696 KB
testcase_06 AC 41 ms
57,888 KB
testcase_07 AC 40 ms
57,632 KB
testcase_08 AC 113 ms
57,740 KB
testcase_09 AC 38 ms
57,656 KB
testcase_10 AC 43 ms
58,196 KB
testcase_11 AC 151 ms
58,028 KB
testcase_12 AC 134 ms
57,792 KB
testcase_13 AC 38 ms
57,612 KB
testcase_14 AC 42 ms
57,608 KB
testcase_15 AC 41 ms
57,784 KB
testcase_16 AC 131 ms
58,076 KB
testcase_17 AC 79 ms
57,696 KB
testcase_18 AC 192 ms
57,852 KB
testcase_19 AC 36 ms
57,476 KB
testcase_20 AC 39 ms
57,512 KB
testcase_21 AC 64 ms
57,464 KB
testcase_22 AC 55 ms
57,852 KB
testcase_23 AC 53 ms
57,956 KB
testcase_24 AC 49 ms
58,032 KB
testcase_25 AC 92 ms
57,588 KB
testcase_26 AC 151 ms
57,952 KB
testcase_27 AC 60 ms
58,240 KB
testcase_28 AC 83 ms
57,692 KB
testcase_29 AC 35 ms
57,976 KB
testcase_30 AC 34 ms
57,448 KB
testcase_31 AC 34 ms
58,316 KB
testcase_32 AC 97 ms
57,960 KB
evil_2_big_1.txt AC 1,371 ms
57,752 KB
evil_2_big_2.txt AC 1,698 ms
57,900 KB
evil_2_big_3.txt AC 1,409 ms
57,592 KB
evil_big_1.txt AC 1,652 ms
57,812 KB
evil_big_2.txt AC 1,719 ms
57,660 KB
evil_big_3.txt AC 1,698 ms
57,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

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

int argmax_segt (int t[][2], int a, int b, int size) {
  int ans = 0;
  int max = argmax_segt_rec(t, a, b, 0, 0, size, &ans);
  return ans;
}

int main () {
  int n = 0;
  int a[75000] = {};
  int i = 0;
  int k = 0;
  int ret = 0;
  
  int res = 0;
  
  int xor = 0;
  int p = 0;
  
  int size = 1;
  int segt[17][300000][2] = {};
  
  res = scanf("%d", &n);
  
  while (size < n) {
    size *= 2;
  }
  
  for (int i = 0; i < n; i++) {
    res = scanf("%d", a+i);
    xor ^= a[i];
    for (int j = 0; j < 17; j++) {
      set_segt(segt[j], i, (a[i]&(1<<j)), size);
    }
  }
  
  if (xor > 0) {
    p = 1;
  }
  printf("%d\n", p);
  fflush(stdout);
  
  while (ret >= 0) {
    if (p > 0) {
      int b = 16;
      while ((xor&(1<<b)) <= 0) {
        b--;
      }
      i = argmax_segt(segt[b], 0, n, size);
      xor ^= a[i];
      k = a[i]-xor;
      a[i] = xor;
      xor = 0;
      for (int j = 0; j < 17; j++) {
        set_segt(segt[j], i, (a[i]&(1<<j)), size);
      }
      printf("%d %d\n", i+1, k);
      fflush(stdout);
      scanf("%d", &ret);
    } else {
      res = scanf("%d", &i);
      res = scanf("%d", &k);
      res = scanf("%d", &ret);
      xor ^= a[i-1];
      a[i-1] -= k;
      xor ^= a[i-1];
      for (int j = 0; j < 17; j++) {
        set_segt(segt[j], i-1, (a[i-1]&(1<<j)), size);
      }
    }
    p = 1-p;
  }
  
  return 0;
}
0