結果
問題 | No.1332 Range Nearest Query |
ユーザー | maspy |
提出日時 | 2021-01-08 23:12:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,484 ms / 2,500 ms |
コード長 | 1,562 bytes |
コンパイル時間 | 586 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 205,360 KB |
最終ジャッジ日時 | 2024-11-16 16:35:16 |
合計ジャッジ時間 | 68,744 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
51,968 KB |
testcase_01 | AC | 40 ms
52,224 KB |
testcase_02 | AC | 39 ms
52,224 KB |
testcase_03 | AC | 2,387 ms
180,196 KB |
testcase_04 | AC | 2,302 ms
179,556 KB |
testcase_05 | AC | 2,184 ms
180,576 KB |
testcase_06 | AC | 1,183 ms
197,784 KB |
testcase_07 | AC | 1,152 ms
197,924 KB |
testcase_08 | AC | 1,042 ms
197,536 KB |
testcase_09 | AC | 1,040 ms
197,524 KB |
testcase_10 | AC | 1,059 ms
197,788 KB |
testcase_11 | AC | 1,072 ms
197,532 KB |
testcase_12 | AC | 1,090 ms
198,312 KB |
testcase_13 | AC | 1,086 ms
198,056 KB |
testcase_14 | AC | 1,055 ms
197,636 KB |
testcase_15 | AC | 1,065 ms
197,292 KB |
testcase_16 | AC | 2,188 ms
203,944 KB |
testcase_17 | AC | 2,291 ms
205,216 KB |
testcase_18 | AC | 2,268 ms
205,232 KB |
testcase_19 | AC | 2,146 ms
204,704 KB |
testcase_20 | AC | 2,231 ms
204,968 KB |
testcase_21 | AC | 2,211 ms
205,356 KB |
testcase_22 | AC | 2,484 ms
204,576 KB |
testcase_23 | AC | 2,142 ms
204,964 KB |
testcase_24 | AC | 2,183 ms
205,360 KB |
testcase_25 | AC | 2,126 ms
205,080 KB |
testcase_26 | AC | 1,150 ms
203,188 KB |
testcase_27 | AC | 1,158 ms
198,584 KB |
testcase_28 | AC | 260 ms
109,568 KB |
testcase_29 | AC | 319 ms
109,952 KB |
testcase_30 | AC | 341 ms
109,056 KB |
testcase_31 | AC | 212 ms
109,568 KB |
testcase_32 | AC | 396 ms
109,568 KB |
testcase_33 | AC | 361 ms
109,568 KB |
testcase_34 | AC | 225 ms
109,824 KB |
testcase_35 | AC | 255 ms
110,080 KB |
testcase_36 | AC | 248 ms
109,184 KB |
testcase_37 | AC | 331 ms
108,928 KB |
testcase_38 | AC | 1,682 ms
146,464 KB |
testcase_39 | AC | 1,038 ms
114,944 KB |
testcase_40 | AC | 2,136 ms
200,708 KB |
testcase_41 | AC | 1,419 ms
119,040 KB |
testcase_42 | AC | 1,757 ms
144,896 KB |
testcase_43 | AC | 1,618 ms
129,224 KB |
testcase_44 | AC | 2,004 ms
168,512 KB |
testcase_45 | AC | 1,895 ms
162,100 KB |
testcase_46 | AC | 1,593 ms
138,780 KB |
testcase_47 | AC | 1,877 ms
154,276 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 = list(map(int, readline().split())) Q = int(readline()) m = map(int, read().split()) query = zip(m, m, m) main(X, query)