結果

問題 No.2080 Simple Nim Query
ユーザー rlangevinrlangevin
提出日時 2023-03-17 12:42:17
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,768 bytes
コンパイル時間 1,412 ms
コンパイル使用メモリ 81,436 KB
実行使用メモリ 79,984 KB
最終ジャッジ日時 2023-10-18 13:35:17
合計ジャッジ時間 8,006 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,588 KB
testcase_01 AC 38 ms
53,588 KB
testcase_02 AC 38 ms
53,588 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

class Fenwick_Tree:
    def __init__(self, n):
        self._n = n
        self.data = [0] * n
 
    def add(self, p, x):
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p
 
    def sum(self, l, r):
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)
 
    def _sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s
    
    def get(self, k):
        k += 1
        x, r = 0, 1
        while r < self._n:
            r <<= 1
        len = r
        while len:
            if x + len - 1 < self._n:
                if self.data[x + len - 1] < k:
                    k -= self.data[x + len - 1]
                    x += len
            len >>= 1
        return x

N, Q = map(int, readline().split())
A = list(map(int, readline().split()))
BIT = Fenwick_Tree(N)
for i in range(N):
    if A[i] == 1:
        BIT.add(i, 1)

for _ in range(Q):
    T, X, Y = map(int, readline().split())
    X -= 1
    if T == 1:
        if A[X] == 1:
            BIT.add(i, -1)
        if Y == 1:
            BIT.add(i, 1)
        A[X] = Y
    else:
        v = BIT.sum(X, Y)
        if v == Y - X:
            print("F") if v % 2 else print("S")
        else:
            if A[Y - 1] != 1:
                print("F")
            else:
                yes = Y - 1
                no = X
                while yes - no != 1:
                    mid = (yes + no)//2
                    if BIT.sum(mid, Y) == Y - mid:
                        yes = mid
                    else:
                        no = mid
                print("F") if yes % 2 == 0 else print("S")
0