結果

問題 No.789 範囲の合計
ユーザー Kiri8128Kiri8128
提出日時 2019-04-16 01:53:11
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 824 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 81,608 KB
実行使用メモリ 109,716 KB
最終ジャッジ日時 2023-10-22 06:55:14
合計ジャッジ時間 13,008 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import sys
input = sys.stdin.readline
from bisect import bisect_left as bl

N = 18
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