結果

問題 No.789 範囲の合計
ユーザー FuyuruFuyuru
提出日時 2024-02-16 17:58:20
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 900 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 172,484 KB
最終ジャッジ日時 2024-02-16 17:58:28
合計ジャッジ時間 6,594 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,616 KB
testcase_01 AC 41 ms
55,616 KB
testcase_02 MLE -
testcase_03 AC 133 ms
76,200 KB
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 AC 133 ms
76,056 KB
testcase_08 AC 370 ms
127,048 KB
testcase_09 AC 343 ms
120,792 KB
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 AC 39 ms
55,616 KB
testcase_14 AC 40 ms
55,616 KB
権限があれば一括ダウンロードができます

ソースコード

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