結果

問題 No.789 範囲の合計
ユーザー kohei2019kohei2019
提出日時 2022-07-29 01:02:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 862 ms / 1,000 ms
コード長 804 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 47,616 KB
最終ジャッジ日時 2023-09-25 19:40:56
合計ジャッジ時間 8,633 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,856 KB
testcase_01 AC 16 ms
7,924 KB
testcase_02 AC 804 ms
40,644 KB
testcase_03 AC 435 ms
16,488 KB
testcase_04 AC 760 ms
40,144 KB
testcase_05 AC 728 ms
40,232 KB
testcase_06 AC 749 ms
40,360 KB
testcase_07 AC 411 ms
17,024 KB
testcase_08 AC 593 ms
29,496 KB
testcase_09 AC 577 ms
28,880 KB
testcase_10 AC 862 ms
47,616 KB
testcase_11 AC 725 ms
39,960 KB
testcase_12 AC 716 ms
39,952 KB
testcase_13 AC 15 ms
7,800 KB
testcase_14 AC 15 ms
7,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)

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