結果
問題 | No.1332 Range Nearest Query |
ユーザー | maspy |
提出日時 | 2021-01-08 22:46:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,475 ms / 2,500 ms |
コード長 | 1,564 bytes |
コンパイル時間 | 1,611 ms |
コンパイル使用メモリ | 81,280 KB |
実行使用メモリ | 268,092 KB |
最終ジャッジ日時 | 2024-11-16 14:17:05 |
合計ジャッジ時間 | 68,279 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
51,968 KB |
testcase_01 | AC | 41 ms
51,968 KB |
testcase_02 | AC | 41 ms
52,224 KB |
testcase_03 | AC | 2,043 ms
249,940 KB |
testcase_04 | AC | 2,109 ms
250,072 KB |
testcase_05 | AC | 2,092 ms
250,064 KB |
testcase_06 | AC | 1,112 ms
264,760 KB |
testcase_07 | AC | 1,105 ms
264,628 KB |
testcase_08 | AC | 1,094 ms
264,892 KB |
testcase_09 | AC | 1,139 ms
264,884 KB |
testcase_10 | AC | 1,097 ms
264,888 KB |
testcase_11 | AC | 1,100 ms
264,888 KB |
testcase_12 | AC | 1,087 ms
264,764 KB |
testcase_13 | AC | 1,127 ms
264,764 KB |
testcase_14 | AC | 1,101 ms
264,760 KB |
testcase_15 | AC | 1,094 ms
264,888 KB |
testcase_16 | AC | 2,166 ms
266,300 KB |
testcase_17 | AC | 2,160 ms
266,164 KB |
testcase_18 | AC | 2,254 ms
265,136 KB |
testcase_19 | AC | 2,475 ms
266,336 KB |
testcase_20 | AC | 2,255 ms
265,896 KB |
testcase_21 | AC | 2,118 ms
266,288 KB |
testcase_22 | AC | 2,147 ms
266,168 KB |
testcase_23 | AC | 2,169 ms
267,960 KB |
testcase_24 | AC | 2,176 ms
268,092 KB |
testcase_25 | AC | 2,225 ms
266,168 KB |
testcase_26 | AC | 1,227 ms
264,988 KB |
testcase_27 | AC | 1,190 ms
265,272 KB |
testcase_28 | AC | 269 ms
108,800 KB |
testcase_29 | AC | 333 ms
108,800 KB |
testcase_30 | AC | 355 ms
109,056 KB |
testcase_31 | AC | 233 ms
108,928 KB |
testcase_32 | AC | 410 ms
108,800 KB |
testcase_33 | AC | 378 ms
108,800 KB |
testcase_34 | AC | 250 ms
108,800 KB |
testcase_35 | AC | 277 ms
108,928 KB |
testcase_36 | AC | 275 ms
108,672 KB |
testcase_37 | AC | 336 ms
108,928 KB |
testcase_38 | AC | 1,721 ms
185,204 KB |
testcase_39 | AC | 1,004 ms
113,408 KB |
testcase_40 | AC | 2,185 ms
263,876 KB |
testcase_41 | AC | 1,385 ms
132,840 KB |
testcase_42 | AC | 1,759 ms
182,300 KB |
testcase_43 | AC | 1,594 ms
150,044 KB |
testcase_44 | AC | 1,901 ms
224,484 KB |
testcase_45 | AC | 1,929 ms
198,764 KB |
testcase_46 | AC | 1,616 ms
169,448 KB |
testcase_47 | AC | 1,854 ms
196,680 KB |
ソースコード
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)