結果

問題 No.789 範囲の合計
ユーザー kohei2019kohei2019
提出日時 2022-07-29 00:53:41
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 922 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 137,008 KB
最終ジャッジ日時 2023-09-25 19:31:22
合計ジャッジ時間 5,235 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,300 KB
testcase_01 AC 72 ms
71,380 KB
testcase_02 MLE -
testcase_03 AC 212 ms
90,584 KB
testcase_04 AC 353 ms
122,244 KB
testcase_05 AC 336 ms
121,748 KB
testcase_06 MLE -
testcase_07 AC 209 ms
90,672 KB
testcase_08 AC 275 ms
108,300 KB
testcase_09 AC 279 ms
105,932 KB
testcase_10 MLE -
testcase_11 AC 340 ms
126,088 KB
testcase_12 AC 327 ms
126,200 KB
testcase_13 AC 73 ms
71,288 KB
testcase_14 AC 72 ms
71,288 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 = set()
ss.add(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)+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