結果
問題 | No.789 範囲の合計 |
ユーザー |
![]() |
提出日時 | 2021-03-23 23:42:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 384 ms / 1,000 ms |
コード長 | 760 bytes |
コンパイル時間 | 2,743 ms |
コンパイル使用メモリ | 82,156 KB |
実行使用メモリ | 127,472 KB |
最終ジャッジ日時 | 2024-11-26 07:09:32 |
合計ジャッジ時間 | 5,795 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
class DynamicBIT: def __init__(self, MAX=10**9): self.data = dict() self.MAX = MAX def add(self, i, x): i += 1 while i <= self.MAX: if i not in self.data: self.data[i] = 0 self.data[i] += x i += i & -i def acc(self, i): res = 0 while i: if i in self.data: res += self.data[i] i -= i & -i return res def prod(self, l, r): return self.acc(r) - self.acc(l) import sys input = sys.stdin.readline q = int(input()) B = DynamicBIT(10**9+1) ans = 0 for _ in range(q): t, p, x = map(int, input().split()) if t == 0: B.add(p, x) else: ans += B.prod(p, x+1) print(ans)