結果

問題 No.1332 Range Nearest Query
ユーザー convexineqconvexineq
提出日時 2021-01-09 16:05:21
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,137 bytes
コンパイル時間 767 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 212,924 KB
最終ジャッジ日時 2024-04-28 23:32:05
合計ジャッジ時間 85,218 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
52,480 KB
testcase_01 AC 43 ms
52,352 KB
testcase_02 AC 47 ms
51,968 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 AC 1,559 ms
210,636 KB
testcase_07 AC 1,479 ms
210,276 KB
testcase_08 AC 1,457 ms
210,216 KB
testcase_09 AC 1,532 ms
210,372 KB
testcase_10 AC 1,421 ms
210,376 KB
testcase_11 AC 1,439 ms
210,380 KB
testcase_12 AC 1,453 ms
210,132 KB
testcase_13 AC 1,435 ms
210,444 KB
testcase_14 AC 1,457 ms
210,372 KB
testcase_15 AC 1,570 ms
210,364 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 AC 867 ms
210,288 KB
testcase_27 AC 827 ms
210,044 KB
testcase_28 AC 383 ms
77,184 KB
testcase_29 AC 425 ms
77,488 KB
testcase_30 AC 477 ms
77,108 KB
testcase_31 AC 329 ms
77,056 KB
testcase_32 AC 516 ms
78,352 KB
testcase_33 AC 510 ms
77,820 KB
testcase_34 AC 350 ms
76,928 KB
testcase_35 AC 378 ms
76,800 KB
testcase_36 AC 378 ms
77,580 KB
testcase_37 AC 399 ms
76,928 KB
testcase_38 AC 2,261 ms
136,728 KB
testcase_39 AC 1,336 ms
84,320 KB
testcase_40 TLE -
testcase_41 TLE -
testcase_42 AC 2,232 ms
135,376 KB
testcase_43 AC 2,030 ms
111,472 KB
testcase_44 AC 2,438 ms
169,776 KB
testcase_45 AC 2,468 ms
162,084 KB
testcase_46 AC 2,129 ms
119,848 KB
testcase_47 AC 2,262 ms
155,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def merge(a,b):
   la,lb = len(a),len(b)
   res = [0]*(la+lb)
   ia = ib = 0
   for i in range(la+lb):
       if ib==lb:
           res[i:] = a[ia:]
           return res
       if ia==la:
           res[i:] = b[ib:]
           return res
       if a[ia] < b[ib]:
           res[i] = a[ia]
           ia += 1
       else:
           res[i] = b[ib]
           ib += 1
   return res

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