結果

問題 No.789 範囲の合計
ユーザー titiatitia
提出日時 2019-02-09 01:14:05
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 643 bytes
コンパイル時間 1,461 ms
コンパイル使用メモリ 86,732 KB
実行使用メモリ 146,992 KB
最終ジャッジ日時 2023-09-14 04:02:30
合計ジャッジ時間 4,247 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,196 KB
testcase_01 AC 64 ms
71,004 KB
testcase_02 MLE -
testcase_03 AC 149 ms
87,868 KB
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 AC 155 ms
87,656 KB
testcase_08 AC 194 ms
110,256 KB
testcase_09 RE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 RE -
testcase_14 RE -
権限があれば一括ダウンロードができます

ソースコード

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