結果

問題 No.789 範囲の合計
ユーザー titiatitia
提出日時 2019-05-24 20:43:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 676 ms / 1,000 ms
コード長 641 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 11,916 KB
実行使用メモリ 55,740 KB
最終ジャッジ日時 2023-10-17 12:03:10
合計ジャッジ時間 7,245 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,036 KB
testcase_01 AC 28 ms
10,036 KB
testcase_02 AC 639 ms
48,748 KB
testcase_03 AC 308 ms
24,672 KB
testcase_04 AC 591 ms
48,384 KB
testcase_05 AC 568 ms
48,280 KB
testcase_06 AC 616 ms
48,480 KB
testcase_07 AC 281 ms
24,968 KB
testcase_08 AC 452 ms
36,960 KB
testcase_09 AC 423 ms
37,088 KB
testcase_10 AC 676 ms
55,740 KB
testcase_11 AC 586 ms
48,128 KB
testcase_12 AC 552 ms
48,128 KB
testcase_13 AC 28 ms
10,036 KB
testcase_14 AC 28 ms
10,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

SET=set()
for x,a,b in Q:
    if x==0:
        SET.add(a)
    else:
        SET.add(a)
        SET.add(b)

DICT={x:i for i,x in enumerate(sorted(SET))}
N=len(DICT)+2

BIT=[0]*N

def update(v,w):#vにwを加える
    while v<N:
        BIT[v]+=w
        v+=(v&(-v))

def getvalue(v):#0~vの区間の和を求める
    ANS=0
    while v>0:
        ANS+=BIT[v]
        v-=(v&(-v))
    return ANS

ANS=0
for x,a,b in Q:
    if x==0:
        update(DICT[a]+1,b)
    else:
        ANS+=getvalue(DICT[b]+1)-getvalue(DICT[a])

print(ANS)
0