結果
問題 |
No.789 範囲の合計
|
ユーザー |
|
提出日時 | 2022-07-29 01:07:04 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 940 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 131,092 KB |
最終ジャッジ日時 | 2024-07-18 15:33:15 |
合計ジャッジ時間 | 3,568 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 MLE * 1 |
ソースコード
class BIT(): def __init__(self, n): self.n = n self.data = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): # assert i > 0 while i <= self.n: self.data[i] += x i += i & -i def get(self, i, j): return self.sum(j) - self.sum(i) import sys input = sys.stdin.readline def main(): N = int(input()) lsQ = [] ss = set([0]) for i in range(N): a,x,y = map(int,input().split()) lsQ.append((a,x,y)) if a == 0: ss.add(x) else: ss.add(x) ss.add(y) dic = {x:i+1 for i,x in enumerate(sorted(ss))} ans = 0 BI = BIT(len(ss)) for a,x,y in lsQ: if a == 0: BI.add(dic[x],y) else: ans += BI.get(dic[x]-1, dic[y]) print(ans) main()