結果

問題 No.2080 Simple Nim Query
ユーザー tnakao0123tnakao0123
提出日時 2022-09-29 09:52:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 3,000 ms
コード長 1,766 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 52,224 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 02:51:06
合計ジャッジ時間 2,217 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 44 ms
4,376 KB
testcase_04 AC 45 ms
4,380 KB
testcase_05 AC 110 ms
4,380 KB
testcase_06 AC 110 ms
4,380 KB
testcase_07 AC 110 ms
4,380 KB
testcase_08 AC 102 ms
4,380 KB
testcase_09 AC 104 ms
4,380 KB
testcase_10 AC 72 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2080.cc:  No.2080 Simple Nim Query - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

template <typename T>
struct BIT {
  int n;
  vector<T> bits;
  
  BIT() {}
  BIT(int _n) { init(_n); }

  void init(int _n) {
    n = _n;
    bits.assign(n + 1, 0);
  }

  T sum(int x) {
    x = min(x, n);
    T s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, T v) {
    if (x <= 0) return;
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }

  int lower_bound(T v) {
    int	k = 1;
    while ((k << 1) <= n) k <<=	1;
    int	x = 0;
    for	(; k > 0; k >>= 1)
      if (x + k <= n && bits[x + k] < v) {
        x += k;
        v -= bits[x];
      }
    return x + 1;
  }
};

/* global variables */

int as[MAX_N];
BIT<int> bit;

/* subroutines */

/* main */

int main() {
  int n, qn;
  scanf("%d%d", &n, &qn);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  bit.init(n);
  for (int i = 0; i < n; i++) {
    if (as[i] == 1) bit.add(i + 1, 1);
    else as[i] = 0;
  }

  while (qn--) {
    int t, x, y;
    scanf("%d%d%d", &t, &x, &y), x--;

    if (t == 1) {
      y = (y == 1) ? 1 : 0;

      if (as[x] != y) {
	if (as[x] == 1) bit.add(x + 1, -1);
	else bit.add(x + 1, 1);
	as[x] = y;
      }
    }
    else {
      int k0 = x - 1, k1 = y;
      int sy = bit.sum(y);
      while (k0 + 1 < k1) {
	int k = (k0 + k1) / 2;
	if (sy - bit.sum(k) != y - k) k0 = k;
	else k1 = k;
      }
      //printf("2 %d %d -> k0=%d\n", x, y, k1);

      int l = y - k1;
      if (x == k1) l++;
      if (! (l & 1)) puts("F");
      else puts("S");
    }
  }

  return 0;
}
0