結果
問題 | No.1332 Range Nearest Query |
ユーザー | maspy |
提出日時 | 2021-01-08 22:59:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,409 ms / 2,500 ms |
コード長 | 1,570 bytes |
コンパイル時間 | 566 ms |
コンパイル使用メモリ | 82,064 KB |
実行使用メモリ | 225,792 KB |
最終ジャッジ日時 | 2024-11-16 15:07:32 |
合計ジャッジ時間 | 70,922 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,700 KB |
testcase_01 | AC | 39 ms
52,216 KB |
testcase_02 | AC | 37 ms
53,292 KB |
testcase_03 | AC | 2,220 ms
209,900 KB |
testcase_04 | AC | 2,200 ms
209,556 KB |
testcase_05 | AC | 2,240 ms
210,316 KB |
testcase_06 | AC | 1,103 ms
217,884 KB |
testcase_07 | AC | 1,121 ms
218,312 KB |
testcase_08 | AC | 1,129 ms
217,844 KB |
testcase_09 | AC | 1,126 ms
217,984 KB |
testcase_10 | AC | 1,118 ms
217,896 KB |
testcase_11 | AC | 1,135 ms
217,968 KB |
testcase_12 | AC | 1,140 ms
218,220 KB |
testcase_13 | AC | 1,152 ms
217,844 KB |
testcase_14 | AC | 1,150 ms
218,164 KB |
testcase_15 | AC | 1,160 ms
218,268 KB |
testcase_16 | AC | 2,297 ms
224,268 KB |
testcase_17 | AC | 2,388 ms
225,788 KB |
testcase_18 | AC | 2,409 ms
225,604 KB |
testcase_19 | AC | 2,330 ms
225,276 KB |
testcase_20 | AC | 2,401 ms
225,784 KB |
testcase_21 | AC | 2,397 ms
225,456 KB |
testcase_22 | AC | 2,309 ms
224,508 KB |
testcase_23 | AC | 2,334 ms
225,232 KB |
testcase_24 | AC | 2,389 ms
225,792 KB |
testcase_25 | AC | 2,346 ms
224,540 KB |
testcase_26 | AC | 1,235 ms
223,368 KB |
testcase_27 | AC | 1,238 ms
219,008 KB |
testcase_28 | AC | 275 ms
109,520 KB |
testcase_29 | AC | 345 ms
109,236 KB |
testcase_30 | AC | 365 ms
109,252 KB |
testcase_31 | AC | 234 ms
109,408 KB |
testcase_32 | AC | 426 ms
108,964 KB |
testcase_33 | AC | 392 ms
109,224 KB |
testcase_34 | AC | 253 ms
109,108 KB |
testcase_35 | AC | 279 ms
109,252 KB |
testcase_36 | AC | 275 ms
109,180 KB |
testcase_37 | AC | 345 ms
109,372 KB |
testcase_38 | AC | 1,882 ms
160,620 KB |
testcase_39 | AC | 1,130 ms
114,260 KB |
testcase_40 | AC | 2,353 ms
221,136 KB |
testcase_41 | AC | 1,562 ms
131,552 KB |
testcase_42 | AC | 1,945 ms
158,744 KB |
testcase_43 | AC | 1,768 ms
141,784 KB |
testcase_44 | AC | 2,094 ms
195,812 KB |
testcase_45 | AC | 2,118 ms
176,608 KB |
testcase_46 | AC | 1,762 ms
153,252 KB |
testcase_47 | AC | 1,934 ms
168,136 KB |
ソースコード
import sys from bisect import bisect read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines INF = 1 << 30 def main(V, query): def merge(A, B): return C N = len(V) seg = [None for _ in range(N + N)] for i in range(N): seg[N + i] = [V[i]] for k in range(N - 1, 0, -1): A, B = seg[k + k], seg[k + k + 1] NA, NB = len(A), len(B) i, j = 0, 0 C = [0] * (NA + NB) for c in range(NA + NB): if i == NA: C[c] = B[j] j += 1 elif j == NB: C[c] = A[i] i += 1 else: if A[i] > B[j]: C[c] = B[j] j += 1 else: C[c] = A[i] i += 1 seg[k] = C def nearest(A, x): n = len(A) i = bisect(A, x) v = INF if i > 0: 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)