結果

問題 No.2080 Simple Nim Query
ユーザー mkawa2mkawa2
提出日時 2022-09-25 21:43:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 904 ms / 3,000 ms
コード長 1,881 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 106,232 KB
最終ジャッジ日時 2023-09-03 02:48:56
合計ジャッジ時間 7,523 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,244 KB
testcase_01 AC 70 ms
71,408 KB
testcase_02 AC 69 ms
71,200 KB
testcase_03 AC 306 ms
82,316 KB
testcase_04 AC 279 ms
81,000 KB
testcase_05 AC 855 ms
102,620 KB
testcase_06 AC 846 ms
106,008 KB
testcase_07 AC 860 ms
106,068 KB
testcase_08 AC 855 ms
105,968 KB
testcase_09 AC 827 ms
106,168 KB
testcase_10 AC 904 ms
106,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

class BitSum:
    def __init__(self, n):
        self.n = n+1
        self.table = [0]*self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

    def sumlr(self, l, r):
        if l >= r: return 0
        if l == 0: return self.sum(r-1)
        return self.sum(r-1)-self.sum(l-1)

n, q = LI()
aa = LI()

bit = BitSum(n)
for i, a in enumerate(aa):
    if a == 1: bit.add(i, 1)

for _ in range(q):
    t, x, y = LI()

    if t == 1:
        x -= 1
        if aa[x] == 1: bit.add(x, -1)
        if y == 1: bit.add(x, 1)
        aa[x] = y
    else:
        if x == y:
            print("F")
        else:
            x -= 1
            l, r = x-1, y
            while l+1 < r:
                m = (l+r)//2
                if bit.sumlr(m, y) == y-m:
                    r = m
                else:
                    l = m
            if ((y-r) & 1) ^ (r == x):
                print("S")
            else:
                print("F")
0