結果

問題 No.789 範囲の合計
ユーザー kohei2019kohei2019
提出日時 2022-07-29 01:00:34
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 812 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 153,844 KB
最終ジャッジ日時 2023-09-25 19:39:08
合計ジャッジ時間 4,965 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,200 KB
testcase_01 AC 68 ms
71,280 KB
testcase_02 MLE -
testcase_03 AC 209 ms
95,148 KB
testcase_04 AC 336 ms
126,472 KB
testcase_05 AC 319 ms
124,808 KB
testcase_06 MLE -
testcase_07 AC 207 ms
94,564 KB
testcase_08 AC 268 ms
116,912 KB
testcase_09 AC 276 ms
115,800 KB
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 AC 68 ms
71,460 KB
testcase_14 AC 70 ms
71,072 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