結果

問題 No.789 範囲の合計
ユーザー stngstng
提出日時 2022-06-25 18:14:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 849 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 82,340 KB
実行使用メモリ 114,276 KB
最終ジャッジ日時 2024-04-27 01:41:58
合計ジャッジ時間 4,819 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 36 ms
53,292 KB
testcase_02 WA -
testcase_03 AC 233 ms
91,104 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 218 ms
92,492 KB
testcase_08 AC 274 ms
114,276 KB
testcase_09 AC 247 ms
109,784 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 35 ms
53,148 KB
testcase_14 AC 36 ms
53,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

n = int(input())
qry = []
idx = []
for i in range(n):
    q = [int(i) for i in input().split()]
    qry.append(q)
    if q[0] == 0:
        idx.append(q[1])

asrt = sorted(set(idx))
adt = { v: i for i, v in enumerate(asrt) }

ki = Bit(len(adt)+1)
ans = 0

for i in range(n):
    q,x,y = qry[i]
    if q == 0:
        ki.add(adt[x]+1,y)
    else:
        l = bisect.bisect_left(asrt,x)
        r = bisect.bisect_left(asrt,y)+1
        ans += ki.sum(r) - ki.sum(l)
        #print(ans,l,r)

print(ans)
0