結果

問題 No.789 範囲の合計
ユーザー titiatitia
提出日時 2019-02-09 01:15:08
言語 PyPy3
(7.3.15)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 641 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 147,172 KB
最終ジャッジ日時 2023-09-14 04:03:38
合計ジャッジ時間 4,031 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,176 KB
testcase_01 AC 64 ms
70,912 KB
testcase_02 MLE -
testcase_03 AC 147 ms
87,936 KB
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 AC 141 ms
88,136 KB
testcase_08 AC 198 ms
110,520 KB
testcase_09 AC 189 ms
108,104 KB
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 AC 63 ms
71,256 KB
testcase_14 AC 61 ms
70,964 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