結果

問題 No.789 範囲の合計
ユーザー kohei2019kohei2019
提出日時 2022-07-29 00:47:09
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,065 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 86,676 KB
実行使用メモリ 134,520 KB
最終ジャッジ日時 2023-09-25 19:22:31
合計ジャッジ時間 5,496 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,152 KB
testcase_01 AC 81 ms
70,864 KB
testcase_02 AC 434 ms
127,828 KB
testcase_03 AC 217 ms
88,868 KB
testcase_04 MLE -
testcase_05 AC 363 ms
124,904 KB
testcase_06 MLE -
testcase_07 AC 216 ms
88,744 KB
testcase_08 AC 282 ms
106,208 KB
testcase_09 AC 293 ms
104,672 KB
testcase_10 MLE -
testcase_11 AC 363 ms
124,368 KB
testcase_12 AC 358 ms
124,200 KB
testcase_13 AC 75 ms
70,672 KB
testcase_14 AC 77 ms
70,884 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 = []
indexls = set()
indexls.add(0)
for i in range(N):
    a,x,y = map(int,input().split())
    if a == 0:
        lsQ.append((0,x,y))
        indexls.add(x)
    else:
        lsQ.append((1,x,y))
        indexls.add(x)
        indexls.add(y)

indexls = list(indexls)
indexls.sort()
dic = dict()
for i in range(len(indexls)):
    dic[indexls[i]] = i+1
ans = 0
BI = BIT(len(indexls)+1)
for i in range(N):
    a,x,y = lsQ[i]
    if a == 0:
        BI.add(dic[x],y)
    else:
        ans += BI.get(dic[x]-1, dic[y])
print(ans)
0