結果
問題 |
No.789 範囲の合計
|
ユーザー |
![]() |
提出日時 | 2025-01-23 20:25:46 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,058 bytes |
コンパイル時間 | 305 ms |
コンパイル使用メモリ | 82,648 KB |
実行使用メモリ | 164,244 KB |
最終ジャッジ日時 | 2025-01-23 20:25:53 |
合計ジャッジ時間 | 5,295 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 MLE * 7 |
ソースコード
import typing class FenwickTree: '''Reference: https://en.wikipedia.org/wiki/Fenwick_tree''' def __init__(self, n: int = 0) -> None: self._n = n self.data = [0] * n def add(self, p: int, x: typing.Any) -> None: assert 0 <= p < self._n p += 1 while p <= self._n: self.data[p - 1] += x p += p & -p def sum(self, left: int, right: int) -> typing.Any: assert 0 <= left <= right <= self._n return self._sum(right) - self._sum(left) def _sum(self, r: int) -> typing.Any: s = 0 while r > 0: s += self.data[r - 1] r -= r & -r return s N = int(input()) TXY = [list(map(int,input().split())) for _ in range(N)] A = set() for t,x,y in TXY: A.add(x) if t == 1: A.add(y) NA = len(A) ft = FenwickTree(NA) B = sorted(list(A)) dic = dict(zip(B,range(NA))) base = [0] * NA ans = 0 for t,x,y in TXY: if t == 0: ft.add(dic[x],y) else: ans += ft.sum(dic[x],dic[y]+1) print(ans)