結果
| 問題 |
No.2080 Simple Nim Query
|
| コンテスト | |
| ユーザー |
terasa
|
| 提出日時 | 2022-09-28 19:55:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 349 ms / 3,000 ms |
| コード長 | 1,987 bytes |
| コンパイル時間 | 150 ms |
| コンパイル使用メモリ | 82,392 KB |
| 実行使用メモリ | 109,432 KB |
| 最終ジャッジ日時 | 2024-06-12 07:29:10 |
| 合計ジャッジ時間 | 3,714 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 |
ソースコード
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')
terasa