結果
問題 | No.2080 Simple Nim Query |
ユーザー | minimum |
提出日時 | 2022-09-25 21:23:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 636 ms / 3,000 ms |
コード長 | 1,415 bytes |
コンパイル時間 | 283 ms |
コンパイル使用メモリ | 87,044 KB |
実行使用メモリ | 106,736 KB |
最終ジャッジ日時 | 2023-09-03 02:47:57 |
合計ジャッジ時間 | 6,109 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 64 ms
71,360 KB |
testcase_01 | AC | 68 ms
71,092 KB |
testcase_02 | AC | 66 ms
71,428 KB |
testcase_03 | AC | 519 ms
79,276 KB |
testcase_04 | AC | 462 ms
79,468 KB |
testcase_05 | AC | 621 ms
102,464 KB |
testcase_06 | AC | 598 ms
106,736 KB |
testcase_07 | AC | 600 ms
106,488 KB |
testcase_08 | AC | 636 ms
106,520 KB |
testcase_09 | AC | 607 ms
106,520 KB |
testcase_10 | AC | 552 ms
106,428 KB |
ソースコード
class Bit: def __init__(self, N): self.size = N self.depth = N.bit_length() self.tree = [0] * (N + 1) def add(self, i, x): while i < self.size: self.tree[i] += x i += i & (-i) def sum0(self, r): s = 0 while r > 0: s += self.tree[r] r -= r & (-r) return s def get_sum(self, l, r): if l <= 1: return self.sum0(r) else: return self.sum0(r) - self.sum0(l - 1) def lower_bound(self, x): s, p = 0, 0 for i in range(self.depth, -1, -1): q = p + (1 << i) if q <= self.size and s + self.tree[q] < x: s += self.tree[q] p += 1 << i return p + 1 N, Q = map(int, input().split()) A = list(map(int, input().split())) bit = Bit(N + 1) for i in range(N): if A[i] > 1: bit.add(i + 1, 1) for i in range(Q): t, x, y = map(int, input().split()) if t == 1: if A[x - 1] == 1 and y > 1: bit.add(x, 1) elif A[x - 1] > 1 and y == 1: bit.add(x, -1) A[x - 1] = y else: if x == y: print('F') else: l = bit.lower_bound(bit.sum0(y)) m = max(l, x) if (y - m) % 2 == 0: print('F') else: print('S')