結果
問題 |
No.789 範囲の合計
|
ユーザー |
![]() |
提出日時 | 2025-01-23 21:09:57 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 740 bytes |
コンパイル時間 | 599 ms |
コンパイル使用メモリ | 12,160 KB |
実行使用メモリ | 49,120 KB |
最終ジャッジ日時 | 2025-01-23 21:10:09 |
合計ジャッジ時間 | 10,555 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 TLE * 1 |
ソースコード
class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N = int(input()) TXY = [list(map(int, input().split())) for _ in range(N)] A = {-1} for t, x, y in TXY: A.add(x) if t == 1: A.add(y) NA = len(A) ft = Bit(NA) A = sorted(list(A)) dic = dict(zip(A, range(NA))) ans = 0 for t, x, y in TXY: if t == 0: ft.add(dic[x], y) else: ans += ft.sum(dic[y]) if dic[x] > 0: ans -= ft.sum(dic[x] - 1) print(ans)