結果

問題 No.789 範囲の合計
ユーザー Kiri8128Kiri8128
提出日時 2019-04-16 01:48:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 786 bytes
コンパイル時間 1,055 ms
コンパイル使用メモリ 11,876 KB
実行使用メモリ 34,376 KB
最終ジャッジ日時 2023-10-22 06:54:52
合計ジャッジ時間 3,151 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

from bisect import bisect_left as bl

N = 17
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
Y = []
Z = set([])
for _ in range(Q):
    t, a, b = map(int, input().split())
    Y.append((t, a, b))
    if t == 1:
        Z |= set([a, b])

Z = list(Z)

for t, a, b in Y:
    if t == 0:
        add(bl(Z, a), b)
    else:
        s += rangesum(bl(Z, a), bl(Z, b)+1)
    
    
print(s)
0