結果

問題 No.2165 Let's Play Nim!
ユーザー 👑 chro_96chro_96
提出日時 2022-12-16 00:44:52
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 2,251 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 31,488 KB
実行使用メモリ 58,756 KB
平均クエリ数 858.54
最終ジャッジ日時 2024-04-27 00:44:00
合計ジャッジ時間 17,013 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
58,480 KB
testcase_01 AC 139 ms
58,448 KB
testcase_02 AC 164 ms
58,292 KB
testcase_03 AC 104 ms
58,708 KB
testcase_04 AC 33 ms
58,420 KB
testcase_05 AC 37 ms
58,216 KB
testcase_06 AC 39 ms
58,708 KB
testcase_07 AC 36 ms
58,180 KB
testcase_08 AC 110 ms
58,536 KB
testcase_09 AC 34 ms
58,704 KB
testcase_10 AC 41 ms
58,428 KB
testcase_11 AC 147 ms
58,416 KB
testcase_12 AC 134 ms
58,188 KB
testcase_13 AC 34 ms
58,460 KB
testcase_14 AC 36 ms
58,472 KB
testcase_15 AC 34 ms
58,416 KB
testcase_16 AC 128 ms
58,656 KB
testcase_17 AC 73 ms
58,392 KB
testcase_18 AC 198 ms
58,472 KB
testcase_19 AC 33 ms
58,252 KB
testcase_20 AC 38 ms
58,652 KB
testcase_21 AC 60 ms
58,452 KB
testcase_22 AC 52 ms
58,296 KB
testcase_23 AC 49 ms
58,652 KB
testcase_24 AC 47 ms
58,384 KB
testcase_25 AC 92 ms
58,756 KB
testcase_26 AC 150 ms
58,700 KB
testcase_27 AC 56 ms
58,288 KB
testcase_28 AC 79 ms
58,676 KB
testcase_29 AC 32 ms
58,720 KB
testcase_30 AC 31 ms
58,376 KB
testcase_31 AC 32 ms
58,400 KB
testcase_32 AC 95 ms
58,352 KB
evil_2_big_1.txt AC 1,354 ms
58,592 KB
evil_2_big_2.txt AC 1,852 ms
58,468 KB
evil_2_big_3.txt AC 1,407 ms
58,468 KB
evil_big_1.txt AC 1,855 ms
58,544 KB
evil_big_2.txt AC 1,906 ms
58,468 KB
evil_big_3.txt AC 1,889 ms
58,408 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