結果
問題 | No.1332 Range Nearest Query |
ユーザー | maspy |
提出日時 | 2021-01-08 22:51:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,113 ms / 2,500 ms |
コード長 | 1,547 bytes |
コンパイル時間 | 464 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 265,400 KB |
最終ジャッジ日時 | 2024-11-16 14:33:07 |
合計ジャッジ時間 | 63,102 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,224 KB |
testcase_01 | AC | 39 ms
52,224 KB |
testcase_02 | AC | 37 ms
52,736 KB |
testcase_03 | AC | 1,958 ms
264,372 KB |
testcase_04 | AC | 1,909 ms
247,132 KB |
testcase_05 | AC | 1,972 ms
264,280 KB |
testcase_06 | AC | 1,025 ms
264,768 KB |
testcase_07 | AC | 1,026 ms
264,768 KB |
testcase_08 | AC | 1,043 ms
265,012 KB |
testcase_09 | AC | 1,022 ms
265,352 KB |
testcase_10 | AC | 1,036 ms
265,400 KB |
testcase_11 | AC | 1,050 ms
264,636 KB |
testcase_12 | AC | 1,050 ms
265,016 KB |
testcase_13 | AC | 1,051 ms
264,636 KB |
testcase_14 | AC | 1,016 ms
264,640 KB |
testcase_15 | AC | 1,041 ms
264,768 KB |
testcase_16 | AC | 2,080 ms
262,580 KB |
testcase_17 | AC | 2,006 ms
265,012 KB |
testcase_18 | AC | 2,052 ms
264,728 KB |
testcase_19 | AC | 2,080 ms
260,028 KB |
testcase_20 | AC | 2,113 ms
260,276 KB |
testcase_21 | AC | 2,041 ms
264,556 KB |
testcase_22 | AC | 2,052 ms
262,336 KB |
testcase_23 | AC | 2,009 ms
264,896 KB |
testcase_24 | AC | 1,991 ms
264,752 KB |
testcase_25 | AC | 1,998 ms
262,456 KB |
testcase_26 | AC | 1,120 ms
264,016 KB |
testcase_27 | AC | 1,151 ms
264,648 KB |
testcase_28 | AC | 261 ms
109,056 KB |
testcase_29 | AC | 319 ms
108,928 KB |
testcase_30 | AC | 331 ms
109,092 KB |
testcase_31 | AC | 223 ms
109,312 KB |
testcase_32 | AC | 394 ms
109,568 KB |
testcase_33 | AC | 358 ms
109,184 KB |
testcase_34 | AC | 239 ms
109,440 KB |
testcase_35 | AC | 262 ms
109,056 KB |
testcase_36 | AC | 259 ms
109,056 KB |
testcase_37 | AC | 328 ms
109,440 KB |
testcase_38 | AC | 1,612 ms
178,924 KB |
testcase_39 | AC | 1,006 ms
114,176 KB |
testcase_40 | AC | 2,092 ms
255,428 KB |
testcase_41 | AC | 1,333 ms
133,788 KB |
testcase_42 | AC | 1,689 ms
178,068 KB |
testcase_43 | AC | 1,519 ms
150,520 KB |
testcase_44 | AC | 1,844 ms
219,108 KB |
testcase_45 | AC | 1,824 ms
208,360 KB |
testcase_46 | AC | 1,580 ms
165,228 KB |
testcase_47 | AC | 1,694 ms
194,500 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(C, A, B): NA, NB = len(A), len(B) i, j = 0, 0 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].append(V[i]) for i in range(N - 1, 0, -1): merge(seg[i], seg[i + i], seg[i + i + 1]) 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)