結果

問題 No.789 範囲の合計
ユーザー ntuda
提出日時 2025-01-23 21:09:30
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 740 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 82,068 KB
実行使用メモリ 136,360 KB
最終ジャッジ日時 2025-01-23 21:09:35
合計ジャッジ時間 4,752 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 MLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0