結果

問題 No.789 範囲の合計
ユーザー titiatitia
提出日時 2019-02-08 23:15:17
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 666 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 126,048 KB
最終ジャッジ日時 2023-09-14 03:57:08
合計ジャッジ時間 3,958 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,404 KB
testcase_01 AC 70 ms
70,996 KB
testcase_02 AC 299 ms
126,048 KB
testcase_03 AC 214 ms
99,904 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

LIST=[]
for x,a,b in Q:
    if x==0:
        LIST.append(a)
    else:
        LIST.append(a)
        LIST.append(b)

LIST.sort()
N=len(LIST)
DICT=dict()

for i in range(N):
    DICT[LIST[i]]=i

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],b)
    else:
        ANS+=getvalue(DICT[b])-getvalue(DICT[a]-1)

print(ANS)
0