結果

問題 No.2080 Simple Nim Query
ユーザー Akijin_007Akijin_007
提出日時 2022-09-25 21:37:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 600 ms / 3,000 ms
コード長 1,923 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 123,084 KB
最終ジャッジ日時 2023-09-03 02:48:43
合計ジャッジ時間 5,916 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,276 KB
testcase_01 AC 67 ms
71,424 KB
testcase_02 AC 69 ms
71,268 KB
testcase_03 AC 410 ms
106,120 KB
testcase_04 AC 374 ms
107,700 KB
testcase_05 AC 565 ms
123,084 KB
testcase_06 AC 588 ms
115,240 KB
testcase_07 AC 572 ms
112,900 KB
testcase_08 AC 600 ms
113,148 KB
testcase_09 AC 583 ms
114,060 KB
testcase_10 AC 407 ms
115,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#int(input())
#map(int, input().split())
#list(map(int, input().split()))

class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x,y : max(x,y), default=-1):
        self.size = 2**(size-1).bit_length() # 簡単のため要素数Nを2冪にする
        self.default = default
        self.dat = [default]*(self.size*2) # 要素を単位元で初期化
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res

N, Q = map(int, input().split())
A = list(map(int, input().split()))
T = [0] * Q
for i in range(Q):
    T[i] = list(map(int, input().split()))

s = SegmentTree(N)
for i in range(N):
    if A[i] != 1:
        s.update(i, i)
    else:
        s.update(i, -1)

ans = []

for k in range(Q):
    t, x, y = T[k]
    if t == 1:
        if y == 1:
            s.update(x-1, -1)
        else:
            s.update(x-1, x-1)
    else:
        a = s.query(x-1, y)
        if a == -1:
            if (y-x) % 2 == 0:
                ans.append("F")
            else:
                ans.append("S")
        else:
            if (y-1 - a) % 2 == 0:
                ans.append("F")
            else:
                ans.append("S")

for x in ans:
    print(x)

0