結果

問題 No.789 範囲の合計
ユーザー Fuyuru
提出日時 2024-02-16 17:58:20
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 900 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 82,412 KB
実行使用メモリ 172,832 KB
最終ジャッジ日時 2024-09-28 19:20:20
合計ジャッジ時間 6,007 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 MLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys
input = sys.stdin.readline
#print = sys.stdout.write
class BIT:
    def __init__(self,N):
        self.N = N
        self.data = defaultdict(lambda: 0)
    def build(self,A):
        for i in range(1,self.N+1):
            self.data[i] += A[i-1]
            if i+(i&-i) <= self.N:
                self.data[i+(i&-i)] += self.data[i]
    def add(self,i,x):
        i += 1
        while i <= self.N:
            self.data[i] += x
            i += i&-i
    def fold(self,l,r):
        res = 0
        while r > 0:
            res += self.data[r]
            r -= r&-r
        while l > 0:
            res -= self.data[l]
            l -= l&-l
        return res


bit = BIT(1000000001)
Q = int(input())
ans = 0
for _ in range(Q):
    op,x,y = map(int,input().split())
    if op == 0:
        bit.add(x,y)
    else:
        ans += bit.fold(x,y+1)
print(ans)
0