結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,952 KB
testcase_01 AC 16 ms
7,844 KB
testcase_02 AC 763 ms
39,984 KB
testcase_03 AC 523 ms
18,896 KB
testcase_04 AC 757 ms
39,840 KB
testcase_05 AC 711 ms
39,808 KB
testcase_06 AC 734 ms
40,112 KB
testcase_07 AC 520 ms
19,012 KB
testcase_08 AC 609 ms
29,692 KB
testcase_09 AC 578 ms
29,912 KB
testcase_10 AC 819 ms
40,816 KB
testcase_11 AC 696 ms
39,532 KB
testcase_12 AC 682 ms
39,320 KB
testcase_13 AC 16 ms
7,824 KB
testcase_14 AC 16 ms
7,884 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 = [0]
for i in range(N):
    a,x,y = map(int,input().split())
    lsQ.append((a,x,y))
    if a == 0:
        ss.append(x)
    else:
        ss.append(x)
        ss.append(y)
dic = {x:i+1 for i,x in enumerate(sorted(set(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