結果

問題 No.1332 Range Nearest Query
ユーザー convexineqconvexineq
提出日時 2021-01-09 16:09:58
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 794 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 221,728 KB
最終ジャッジ日時 2024-04-28 23:44:17
合計ジャッジ時間 38,430 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
57,856 KB
testcase_01 AC 46 ms
52,096 KB
testcase_02 AC 45 ms
52,352 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 AC 1,351 ms
215,200 KB
testcase_07 AC 1,313 ms
215,208 KB
testcase_08 AC 1,299 ms
215,720 KB
testcase_09 AC 1,301 ms
215,204 KB
testcase_10 AC 1,306 ms
215,216 KB
testcase_11 AC 1,393 ms
215,200 KB
testcase_12 AC 1,424 ms
215,460 KB
testcase_13 AC 1,324 ms
215,196 KB
testcase_14 AC 1,407 ms
215,084 KB
testcase_15 AC 1,452 ms
215,632 KB
testcase_16 TLE -
testcase_17 AC 2,490 ms
215,472 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
*a, = map(int,input().split())

def merge(a,b):
    return sorted(a+b)

N0 = 1<<(n-1).bit_length()
dat = [[]]*(2*N0)
for i in range(n):
    dat[N0+i] = [a[i]]
for k in range(N0-1,0,-1):
    dat[k] = merge(dat[2*k], dat[2*k+1])

def getans(lst,x):
    v = INF
    idx = bisect_left(lst,x)
    if idx < len(lst):
        v = lst[idx]-x
    if idx:
        v = min(v,x-lst[idx-1])
    return v

INF = 10**9
from bisect import bisect_left, bisect_right
Q = int(input())
for _ in range(Q):
    L,R,x = map(int,input().split())
    L += N0-1; R += N0
    ans = INF
    while L < R:
        if R & 1:
            R -= 1
            ans = min(ans,getans(dat[R],x))
        if L & 1:
            ans = min(ans,getans(dat[L],x))
            L += 1
        L >>= 1; R >>= 1
    print(ans)
0