結果

問題 No.1332 Range Nearest Query
ユーザー maspymaspy
提出日時 2021-01-08 22:46:40
言語 PyPy3
(7.3.15)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,564 bytes
コンパイル時間 994 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 532,456 KB
最終ジャッジ日時 2024-12-16 14:59:34
合計ジャッジ時間 81,191 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33 MLE * 4 TLE * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import sys
from bisect import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 1 << 60
def main(V, query):
def merge(A, B):
NA, NB = len(A), len(B)
i, j = 0, 0
C = []
for _ in range(NA + NB):
if i == NA:
C.append(B[j])
j += 1
elif j == NB:
C.append(A[i])
i += 1
else:
if A[i] > B[j]:
C.append(B[j])
j += 1
else:
C.append(A[i])
i += 1
return C
N = len(V)
seg = [[] for _ in range(N + N)]
for i in range(N):
seg[N + i] = [V[i]]
for i in range(N - 1, 0, -1):
seg[i] = merge(seg[i + i], seg[i + i + 1])
def nearest(A, x):
n = len(A)
i = bisect(A, x)
v = INF
if i > 0:
v = min(v, x - A[i - 1])
if i < n:
v = min(v, A[i] - x)
return v
for L, R, x in query:
L -= 1
L += N
R += N
v = INF
while L < R:
if L & 1:
v = min(v, nearest(seg[L], x))
L += 1
if R & 1:
R -= 1
v = min(v, nearest(seg[R], x))
L, R = L >> 1, R >> 1
print(v)
N = int(readline())
X = tuple(map(int, readline().split()))
Q = int(readline())
m = map(int, read().split())
query = tuple(zip(m, m, m))
main(X, query)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0