結果
| 問題 | No.3120 Lower Nim |
| コンテスト | |
| ユーザー |
hir355
|
| 提出日時 | 2025-04-19 05:10:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 439 ms / 2,000 ms |
| コード長 | 1,740 bytes |
| コンパイル時間 | 461 ms |
| コンパイル使用メモリ | 82,364 KB |
| 実行使用メモリ | 96,128 KB |
| 平均クエリ数 | 2685.91 |
| 最終ジャッジ日時 | 2025-04-19 05:11:09 |
| 合計ジャッジ時間 | 14,945 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 43 |
ソースコード
def fn(x, y):
if x[0] > y[0]:
return x
else:
return y
class SegmentTree:
# 初期化処理
# f : SegmentTreeにのせるモノイド
# default : fに対する単位元
def __init__(self, size, f=fn, default=(0, 0)):
self.size = 2**(size-1).bit_length()
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
l >>= 1
if r & 1:
r -= 1
rres = self.f(self.dat[r], rres)
r >>= 1
res = self.f(lres, rres)
return res
n = int(input())
a = list(map(int, input().split()))
seg = SegmentTree(n)
for i in range(n):
seg.update(i, (a[i], i))
b = a[:]
s = sum(a)
k = 1
while s > 0:
if s % 2 == 1:
print('First')
break
for i in range(n):
b[i] //= 2
k *= 2
s = sum(b)
else:
print('Second')
i, x = map(int, input().split())
if int(input()):
exit(0)
i -= 1
seg.update(i, (seg.query(i, i + 1)[0] - x, i))
k = x & -x
while 1:
x, i = seg.query(0, n)
seg.update(i, (x - k, i))
print(i + 1, k)
if int(input()):
exit(0)
i, x = map(int, input().split())
if int(input()):
exit(0)
i -= 1
seg.update(i, (seg.query(i, i + 1)[0] - x, i))
k = x & -x
hir355