結果
| 問題 |
No.1441 MErGe
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-09 14:31:57 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,489 bytes |
| コンパイル時間 | 306 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 117,472 KB |
| 最終ジャッジ日時 | 2024-09-21 13:34:25 |
| 合計ジャッジ時間 | 17,622 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 3 WA * 25 |
ソースコード
#BIT
class BinaryIndexedTree():
def __init__(self, n: int) -> None:
self.n = 1 << (n.bit_length())
self.BIT = [0] * (self.n + 1)
def build(self, init_lis: list) -> None:
for i, v in enumerate(init_lis):
self.add(i, v)
def add(self, i: int, x: int) -> None:
i += 1
while i <= self.n:
self.BIT[i] += x
i += i & -i
def sum(self, l: int, r: int) -> int:
return self._sum(r) - self._sum(l)
def _sum(self, i: int) -> int:
res = 0
while i > 0:
res += self.BIT[i]
i -= i & -i
return res
def binary_search(self, x: int) -> int:
i = self.n
while True:
if i & 1:
if x > self.BIT[i]:
i += 1
break
if x > self.BIT[i]:
x -= self.BIT[i]
i += (i & -i) >> 1
else:
i -= (i & -i) >> 1
return i
n, q = map(int, input().split())
a = list(map(int, input().split()))
from itertools import accumulate
a = [0] + list(accumulate(a))
BIT = BinaryIndexedTree(n)
for i in range(1, n + 1):
BIT.add(i, 1)
for _ in range(q):
t, l, r = map(int, input().split())
if t == 1:
for _ in range(r - l):
i = BIT.binary_search(l + 1)
BIT.add(i, -1)
else:
L = BIT.binary_search(l)
R = BIT.binary_search(r)
print(a[R - 1] - a[L - 2])