結果

問題 No.1441 MErGe
ユーザー gorugo30
提出日時 2021-03-26 22:21:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 848 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 82,148 KB
実行使用メモリ 104,416 KB
最終ジャッジ日時 2024-11-28 23:50:26
合計ジャッジ時間 7,337 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 2 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

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))
0