結果

問題 No.789 範囲の合計
ユーザー kohei2019kohei2019
提出日時 2022-07-29 00:56:16
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 923 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 154,964 KB
最終ジャッジ日時 2023-09-25 19:34:21
合計ジャッジ時間 5,435 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,324 KB
testcase_01 AC 70 ms
71,172 KB
testcase_02 MLE -
testcase_03 AC 212 ms
94,904 KB
testcase_04 AC 345 ms
124,680 KB
testcase_05 AC 334 ms
123,956 KB
testcase_06 MLE -
testcase_07 AC 208 ms
95,460 KB
testcase_08 AC 267 ms
117,940 KB
testcase_09 AC 276 ms
116,828 KB
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 AC 68 ms
71,056 KB
testcase_14 AC 69 ms
71,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT():
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [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
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        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)+1)
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