結果

問題 No.2080 Simple Nim Query
ユーザー 👑 rin204rin204
提出日時 2022-09-26 19:43:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 863 ms / 3,000 ms
コード長 2,405 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 123,084 KB
最終ジャッジ日時 2023-09-03 02:50:27
合計ジャッジ時間 7,772 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,300 KB
testcase_01 AC 70 ms
71,436 KB
testcase_02 AC 68 ms
71,576 KB
testcase_03 AC 711 ms
80,040 KB
testcase_04 AC 565 ms
79,388 KB
testcase_05 AC 761 ms
119,428 KB
testcase_06 AC 863 ms
122,796 KB
testcase_07 AC 855 ms
123,084 KB
testcase_08 AC 858 ms
122,724 KB
testcase_09 AC 859 ms
122,496 KB
testcase_10 AC 591 ms
123,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree:
    def __init__(self, n, e, ope, lst=[]):
        self.N0 = 2 ** (n - 1).bit_length()
        self.e = e
        self.ope = ope
        self.data = [e] * (2 * self.N0)
        if lst:
            for i in range(n):
                self.data[self.N0 + i] = lst[i]
            for i in range(self.N0 - 1, 0, -1):
                self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def build(self):
        for i in range(self.N0 - 1, 0, -1):
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
                
    def update(self, i, x): #a_iの値をxに更新
        i += self.N0
        self.data[i] = x
        while i > 1:
            i >>= 1
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def add(self, i, x):
        self.update(i, x + self.get(i))

    def set(self, i, x):
        self.data[self.N0 + i] = x
    
    def query(self, l, r): #区間[l, r)での演算結果
        if r <= l:
            return self.e
        lres = self.e
        rres = self.e
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                lres = self.ope(lres, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                rres = self.ope(self.data[r], rres)
            l >>= 1
            r >>= 1
        return self.ope(lres, rres)
    
    def get(self, i): #a_iの値を返す
        return self.data[self.N0 + i]

n, Q = map(int, input().split())
A = list(map(int, input().split()))

mask = (1 << 30) - 1
def ope(x, y):
    x0 = x >> 30
    x1 = x & mask
    y0 = y >> 30
    y1 = y & mask

    if y0 == y1:
        z0, z1 = x0 + y0, x1 + y1
    else:
        z0, z1 = x0 + y0, y1
    return (z0 << 30) | z1

B = []
one = (1 << 30) + 1
el = 1 << 30
for a in A:
    if a == 1:
        B.append(one)
    else:
        B.append(el)
seg = SegTree(n, 0, ope, B)

for _ in range(Q):
    t, x, y = map(int, input().split())
    x -= 1
    if t == 1:
        A[x] = y
        if y == 1:
            seg.update(x, one)
        else:
            seg.update(x, el)
    else:
        z = seg.query(x, y)
        z0 = z >> 30
        z1 = z & mask
        if z0 == z1:
            if z0 & 1:
                print("F")
            else:
                print("S")
        elif z1 & 1:
            print("S")
        else:
            print("F")
0