結果
問題 |
No.789 範囲の合計
|
ユーザー |
![]() |
提出日時 | 2024-02-16 18:01:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 333 ms / 1,000 ms |
コード長 | 823 bytes |
コンパイル時間 | 657 ms |
コンパイル使用メモリ | 82,956 KB |
実行使用メモリ | 119,400 KB |
最終ジャッジ日時 | 2024-09-28 19:21:25 |
合計ジャッジ時間 | 4,343 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
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)