結果

問題 No.2080 Simple Nim Query
ユーザー ああいいああいい
提出日時 2022-09-28 10:04:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 806 ms / 3,000 ms
コード長 1,871 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 109,792 KB
最終ジャッジ日時 2023-09-03 02:51:08
合計ジャッジ時間 7,444 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,472 KB
testcase_01 AC 69 ms
71,280 KB
testcase_02 AC 70 ms
71,404 KB
testcase_03 AC 695 ms
81,544 KB
testcase_04 AC 563 ms
79,628 KB
testcase_05 AC 706 ms
106,056 KB
testcase_06 AC 783 ms
109,792 KB
testcase_07 AC 801 ms
109,540 KB
testcase_08 AC 806 ms
109,696 KB
testcase_09 AC 805 ms
109,568 KB
testcase_10 AC 609 ms
109,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


class SegTree:
    #単位元と結合演算はここ変える
    #いろんな種類のsegは作れないかも
    #→changeで変えれる
    
    unit = 0
    def f(self,x,y):
        return max(x,y)

    #頂点は1-index、一番下の段は0-index(bitは1-index)
    def __init__(self,N):
        self.N = N
        self.X = [self.unit] * (N + N)
    def build(self,seq):
        for i,x in enumerate(seq,self.N):
            self.X[i] = x
        for i in range(self.N-1,0,-1):
            self.X[i] = self.f(self.X[i << 1],self.X[i << 1 | 1])
    def set(self,i,x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.f(self.X[i << 1],self.X[i << 1 | 1])
    def fold(self,L,R):
        #区間[L,R)についてfold
        #0 <= L,R <= N にしなきゃダメ
        L += self.N
        R += self.N
        vL = self.unit
        vR = self.unit
        while L < R:
            if L & 1:
                vL = self.f(vL,self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.f(self.X[R],vR)
            L >>= 1
            R >>= 1
        return self.f(vL,vR)
    def change(self,f,unit):
        self.f = f
        self.unit = unit

N,Q = map(int,input().split())
A = list(map(int,input().split()))
l = [i + 1 if A[i] > 1 else 0 for i in range(N)]
seg = SegTree(N)
seg.build(l)

for _ in range(Q):
    t,x,y = map(int,input().split())
    if t == 1:
        if y == 1:
            seg.set(x-1,0)
        else:
            seg.set(x-1,x)
    else:
        u = seg.fold(x-1,y)
        if u == 0:
            if (y - x + 1) & 1:
                print('F')
            else:
                print('S')
        else:
            v = y - u
            if v & 1:
                print('S')
            else:
                print('F')
                
0