結果
| 問題 | No.1441 MErGe |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-26 22:21:01 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 848 bytes |
| 記録 | |
| コンパイル時間 | 298 ms |
| コンパイル使用メモリ | 85,120 KB |
| 実行使用メモリ | 113,136 KB |
| 最終ジャッジ日時 | 2026-05-22 21:50:32 |
| 合計ジャッジ時間 | 6,788 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 2 WA * 26 |
ソースコード
class Fenwick:
def __init__(self, n):
self.n = n
self.data = [0] * (n + 1)
self.depth = n.bit_length()
def getsum(self, i): # 0-indexed [0: i)
res = 0
while i > 0:
res += self.data[i]
i -= i & -i
return res
def add(self, i, x): # 0-indexed
i += 1
while i <= self.n:
self.data[i] += x
i += i & -i
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
A = list(map(int, input().split()))
BITA = Fenwick(N)
for i in range(N):
BITA.add(i, A[i])
BITlr = Fenwick(N)
for i in range(Q):
T, l, r = map(int, input().split())
l -= 1
r -= 1
if T == 1:
BITlr.add(l, r - l)
else:
l += BITlr.getsum(l)
r += BITlr.getsum(r)
print(BITA.getsum(r + 1) - BITA.getsum(l))