結果

問題 No.789 範囲の合計
ユーザー ntuda
提出日時 2025-01-23 20:54:22
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 758 bytes
コンパイル時間 469 ms
コンパイル使用メモリ 81,912 KB
実行使用メモリ 244,056 KB
最終ジャッジ日時 2025-01-23 20:54:41
合計ジャッジ時間 17,555 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 TLE * 5 MLE * 8
権限があれば一括ダウンロードができます

ソースコード

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 = set()
for t, x, y in TXY:
    A.add(x)
    if t == 1:
        A.add(y)

NA = len(A)
ft = Bit(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[y])
        if dic[x] > 0:
            ans -= ft.sum(dic[x] - 1)
print(ans)
0