結果
問題 | No.1332 Range Nearest Query |
ユーザー | maspy |
提出日時 | 2021-01-08 23:11:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,385 ms / 2,500 ms |
コード長 | 1,563 bytes |
コンパイル時間 | 531 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 212,924 KB |
最終ジャッジ日時 | 2024-11-16 16:30:56 |
合計ジャッジ時間 | 68,435 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,096 KB |
testcase_01 | AC | 39 ms
51,968 KB |
testcase_02 | AC | 39 ms
52,352 KB |
testcase_03 | AC | 2,061 ms
196,652 KB |
testcase_04 | AC | 2,007 ms
196,188 KB |
testcase_05 | AC | 2,149 ms
197,080 KB |
testcase_06 | AC | 1,043 ms
204,988 KB |
testcase_07 | AC | 1,063 ms
205,376 KB |
testcase_08 | AC | 1,096 ms
204,860 KB |
testcase_09 | AC | 1,061 ms
205,112 KB |
testcase_10 | AC | 1,117 ms
204,988 KB |
testcase_11 | AC | 1,085 ms
205,264 KB |
testcase_12 | AC | 1,127 ms
205,372 KB |
testcase_13 | AC | 1,172 ms
205,116 KB |
testcase_14 | AC | 1,155 ms
205,232 KB |
testcase_15 | AC | 1,130 ms
204,984 KB |
testcase_16 | AC | 2,303 ms
212,028 KB |
testcase_17 | AC | 2,217 ms
212,916 KB |
testcase_18 | AC | 2,196 ms
212,496 KB |
testcase_19 | AC | 2,131 ms
212,144 KB |
testcase_20 | AC | 2,385 ms
212,920 KB |
testcase_21 | AC | 2,354 ms
212,924 KB |
testcase_22 | AC | 2,194 ms
211,252 KB |
testcase_23 | AC | 2,174 ms
212,284 KB |
testcase_24 | AC | 2,243 ms
212,800 KB |
testcase_25 | AC | 2,206 ms
212,408 KB |
testcase_26 | AC | 1,201 ms
211,004 KB |
testcase_27 | AC | 1,183 ms
206,524 KB |
testcase_28 | AC | 256 ms
109,440 KB |
testcase_29 | AC | 326 ms
110,208 KB |
testcase_30 | AC | 347 ms
108,672 KB |
testcase_31 | AC | 216 ms
109,568 KB |
testcase_32 | AC | 410 ms
109,696 KB |
testcase_33 | AC | 364 ms
109,440 KB |
testcase_34 | AC | 230 ms
109,696 KB |
testcase_35 | AC | 258 ms
110,208 KB |
testcase_36 | AC | 251 ms
109,184 KB |
testcase_37 | AC | 322 ms
108,928 KB |
testcase_38 | AC | 1,749 ms
147,992 KB |
testcase_39 | AC | 1,089 ms
114,432 KB |
testcase_40 | AC | 2,231 ms
208,964 KB |
testcase_41 | AC | 1,433 ms
118,948 KB |
testcase_42 | AC | 1,837 ms
146,212 KB |
testcase_43 | AC | 1,663 ms
130,596 KB |
testcase_44 | AC | 1,972 ms
182,596 KB |
testcase_45 | AC | 1,985 ms
164,688 KB |
testcase_46 | AC | 1,689 ms
140,320 KB |
testcase_47 | AC | 1,829 ms
156,156 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 = zip(m, m, m) main(X, query)