結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,736 KB
testcase_01 AC 43 ms
52,608 KB
testcase_02 AC 44 ms
52,096 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 AC 1,470 ms
217,876 KB
testcase_07 AC 1,472 ms
217,524 KB
testcase_08 AC 1,417 ms
217,908 KB
testcase_09 AC 1,408 ms
218,040 KB
testcase_10 AC 1,448 ms
217,532 KB
testcase_11 AC 1,435 ms
217,912 KB
testcase_12 AC 1,460 ms
218,296 KB
testcase_13 AC 1,470 ms
217,780 KB
testcase_14 AC 1,459 ms
217,656 KB
testcase_15 AC 1,594 ms
217,788 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 934 ms
217,952 KB
testcase_27 AC 873 ms
217,180 KB
testcase_28 AC 393 ms
77,696 KB
testcase_29 AC 439 ms
77,868 KB
testcase_30 AC 486 ms
77,372 KB
testcase_31 AC 328 ms
77,312 KB
testcase_32 AC 520 ms
77,964 KB
testcase_33 AC 491 ms
77,316 KB
testcase_34 AC 365 ms
76,672 KB
testcase_35 AC 383 ms
76,800 KB
testcase_36 AC 394 ms
77,324 KB
testcase_37 AC 412 ms
77,440 KB
testcase_38 AC 2,274 ms
139,916 KB
testcase_39 AC 1,332 ms
84,168 KB
testcase_40 TLE -
testcase_41 AC 1,881 ms
98,600 KB
testcase_42 AC 2,327 ms
138,972 KB
testcase_43 AC 2,032 ms
112,548 KB
testcase_44 AC 2,406 ms
170,052 KB
testcase_45 AC 2,379 ms
163,512 KB
testcase_46 AC 2,115 ms
119,952 KB
testcase_47 AC 2,290 ms
158,828 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 = [None]*(2*N0)
for i in range(n):
    dat[N0+i] = [a[i]]
for i in range(n,N0):
    dat[N0+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