結果

問題 No.789 範囲の合計
ユーザー Kiri8128Kiri8128
提出日時 2019-04-16 01:37:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 603 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 12,016 KB
実行使用メモリ 26,736 KB
最終ジャッジ日時 2023-10-22 06:54:41
合計ジャッジ時間 4,457 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 65 ms
26,248 KB
testcase_02 RE -
testcase_03 TLE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 TLE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 64 ms
26,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = 20
X = [0] * (2**(N+1)-1)

def add(j, x):
    i = 2**N + j - 1
    while i >= 0:
        X[i] += x
        i = (i-1) // 2

def rangeof(i):
    s = (len(bin(i+1))-3)
    l = ((i+1) - (1<<s)) * (1<<N-s)
    r = l + (1<<N-s)
    return (l, r)

def rangesum(a, b, i=0):
    l, r = rangeof(i)
    if l >= b or r <= a:
        return 0
    if a <= l and r <= b:
        return X[i]
    return rangesum(a, b, 2*i+1) + rangesum(a, b, 2*i+2)


Q = int(input())
s = 0
for _ in range(Q):
    t, a, b = map(int, input().split())
    if t == 0:
        add(a, b)
    else:
        s += rangesum(a, b+1)

print(s)
0