結果

問題 No.789 範囲の合計
ユーザー prd_xxxprd_xxx
提出日時 2019-02-08 22:25:07
言語 PyPy3
(7.3.15)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 648 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 148,800 KB
最終ジャッジ日時 2023-09-14 03:48:45
合計ジャッジ時間 8,943 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,200 KB
testcase_01 AC 69 ms
71,424 KB
testcase_02 MLE -
testcase_03 AC 213 ms
88,836 KB
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 AC 212 ms
88,780 KB
testcase_08 AC 255 ms
112,260 KB
testcase_09 AC 248 ms
109,064 KB
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 AC 68 ms
71,044 KB
testcase_14 AC 73 ms
71,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
Q = [tuple(map(int,input().split())) for i in range(N)]
xs = set()
for a,b,c in Q:
    if a == 0:
        xs.add(b)
    else:
        xs.add(b)
        xs.add(c)
order = {x:i for i,x in enumerate(sorted(xs))}

L = len(xs)

bit = [0] * (L+1)
def bit_add(a,w):
    x = a
    while x <= L:
        bit[x] += w
        x += (x & -x)

def bit_sum(a):
    x = a
    ret = 0
    while x > 0:
        ret += bit[x]
        x -= (x & -x)
    return ret

ans = 0
for a,b,c in Q:
    if a == 0:
        x = order[b]
        bit_add(x+1,c)
    else:
        l = order[b]
        r = order[c]
        ans += bit_sum(r+1) - bit_sum(l)
print(ans)
0