結果

問題 No.789 範囲の合計
ユーザー FuyuruFuyuru
提出日時 2024-02-16 18:01:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 397 ms / 1,000 ms
コード長 823 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 118,964 KB
最終ジャッジ日時 2024-02-16 18:02:14
合計ジャッジ時間 5,391 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 397 ms
112,608 KB
testcase_03 AC 129 ms
75,808 KB
testcase_04 AC 392 ms
110,484 KB
testcase_05 AC 340 ms
110,176 KB
testcase_06 AC 366 ms
112,732 KB
testcase_07 AC 135 ms
75,660 KB
testcase_08 AC 316 ms
114,676 KB
testcase_09 AC 296 ms
110,488 KB
testcase_10 AC 355 ms
99,488 KB
testcase_11 AC 339 ms
118,964 KB
testcase_12 AC 319 ms
116,764 KB
testcase_13 AC 37 ms
53,460 KB
testcase_14 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
#print = sys.stdout.write
class BIT:
    def __init__(self,N):
        self.N = N
        self.data = dict()
    def add(self,i,x):
        i += 1
        while i <= self.N:
            if i in self.data:
                self.data[i] += x
            else:
                self.data[i] = x
            i += i&-i
    def fold(self,l,r):
        res = 0
        while r > 0:
            if r in self.data:
                res += self.data[r]
            r -= r&-r
        while l > 0:
            if l in self.data:
                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