結果

問題 No.789 範囲の合計
ユーザー pasoconhoshiipasoconhoshii
提出日時 2019-02-11 22:12:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 832 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 33,316 KB
最終ジャッジ日時 2023-09-26 15:11:47
合計ジャッジ時間 3,536 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
13,116 KB
testcase_01 AC 19 ms
8,652 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

    #!/mnt/c/Users/moiki/bash/env/bin/python
N = int(input())

Q = [ list(map(int, input().split())) for _ in range(N)]

from collections import defaultdict
from bisect import bisect_left, bisect_right, insort_left, insort_right
pairdic = defaultdict(int)

inf = float("inf")
ans = 0
idx_cnt = [(inf,inf)]
for q,x,y in Q:
    if q == 0:
        pairdic[x] += y

        insort_left( idx_cnt, (x,y))
        # idx_cnt.insert( bisect_left(
        # idx_cnt = [ (idx, pairdic[idx]) for idx in pairdic.keys()]
        # idx_cnt = sorted(idx_cnt)

    if q == 1:
        l,r = x,y
        lidx = bisect_left(  idx_cnt, (l,0))
        ridx = bisect_right(  idx_cnt, (r,inf))
        #print(idx_cnt)
        #print(lidx, ridx)
        ans += sum( list(map(lambda x: x[1], idx_cnt))[lidx:ridx], 0)
        # print("ans: ", ans)

print(ans)
0