結果

問題 No.2080 Simple Nim Query
ユーザー terasaterasa
提出日時 2022-09-28 19:55:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 471 ms / 3,000 ms
コード長 1,987 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 111,920 KB
最終ジャッジ日時 2023-09-03 02:51:06
合計ジャッジ時間 5,241 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
72,700 KB
testcase_01 AC 103 ms
72,824 KB
testcase_02 AC 110 ms
72,852 KB
testcase_03 AC 321 ms
83,284 KB
testcase_04 AC 306 ms
83,196 KB
testcase_05 AC 445 ms
108,972 KB
testcase_06 AC 464 ms
111,920 KB
testcase_07 AC 471 ms
111,668 KB
testcase_08 AC 461 ms
111,592 KB
testcase_09 AC 444 ms
111,608 KB
testcase_10 AC 361 ms
111,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
from functools import lru_cache

# for AtCoder Easy test
if __file__ == 'prog.py':
    pass
else:
    sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')

input = sys.stdin.readline


def readints(): return map(int, input().split())
def readlist(): return list(readints())
def readstr(): return input()[:-1]


class SegTree:
    def __init__(self, N, func, e):
        self.N = N
        self.func = func
        self.X = [e] * (N << 1)
        self.e = e

    def build(self, seq):
        for i in range(self.N):
            self.X[self.N + i] = seq[i]
        for i in range(self.N)[::-1]:
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def add(self, i, x):
        i += self.N
        self.X[i] += x
        while i > 1:
            i >>= 1
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def update(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def query(self, L, R):
        L += self.N
        R += self.N
        vL = self.e
        vR = self.e
        while L < R:
            if L & 1:
                vL = self.func(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.func(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.func(vL, vR)


N, Q = readints()
A = readlist()
B = [i if A[i] > 1 else -1 for i in range(N)]
st = SegTree(N, max, -1)
st.build(B)
for _ in range(Q):
    t, x, y = readints()
    if t == 1:
        x -= 1
        st.update(x, x if y > 1 else -1)
    else:
        x -= 1
        m = st.query(x, y)
        if m == -1:
            print('F' if (y - x) & 1 else 'S')
        else:
            print('F' if (y - m) & 1 else 'S')
0