結果

問題 No.789 範囲の合計
ユーザー titiatitia
提出日時 2019-02-08 23:13:03
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 729 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 87,296 KB
実行使用メモリ 142,468 KB
最終ジャッジ日時 2023-09-14 03:56:46
合計ジャッジ時間 3,584 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
75,632 KB
testcase_01 AC 68 ms
70,980 KB
testcase_02 MLE -
testcase_03 TLE -
testcase_04 -- -
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=set()
for x,a,b in Q:
    if x==0:
        LIST.add(a)
    else:
        LIST.add(a)
        LIST.add(b)

LIST=sorted(list(LIST))
N=len(LIST)
DICT=dict()

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

BIT=[0]*N#出現回数をbit indexed treeの形でもっておく.

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