結果
問題 | No.1332 Range Nearest Query |
ユーザー | maspy |
提出日時 | 2021-01-08 23:14:18 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,562 bytes |
コンパイル時間 | 399 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 206,116 KB |
最終ジャッジ日時 | 2024-11-16 17:17:18 |
合計ジャッジ時間 | 75,070 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,480 KB |
testcase_01 | AC | 41 ms
52,480 KB |
testcase_02 | AC | 40 ms
52,224 KB |
testcase_03 | AC | 2,294 ms
180,192 KB |
testcase_04 | AC | 2,285 ms
180,144 KB |
testcase_05 | AC | 2,498 ms
180,848 KB |
testcase_06 | AC | 1,151 ms
198,052 KB |
testcase_07 | AC | 1,140 ms
198,064 KB |
testcase_08 | AC | 1,148 ms
197,668 KB |
testcase_09 | AC | 1,158 ms
197,672 KB |
testcase_10 | AC | 1,140 ms
197,992 KB |
testcase_11 | AC | 1,163 ms
197,540 KB |
testcase_12 | AC | 1,193 ms
198,692 KB |
testcase_13 | AC | 1,193 ms
198,180 KB |
testcase_14 | AC | 1,170 ms
197,676 KB |
testcase_15 | AC | 1,171 ms
197,544 KB |
testcase_16 | AC | 2,448 ms
204,184 KB |
testcase_17 | TLE | - |
testcase_18 | AC | 2,439 ms
205,488 KB |
testcase_19 | AC | 2,455 ms
204,960 KB |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | AC | 2,399 ms
204,460 KB |
testcase_23 | AC | 2,394 ms
205,612 KB |
testcase_24 | AC | 2,463 ms
206,116 KB |
testcase_25 | AC | 2,495 ms
204,968 KB |
testcase_26 | AC | 1,323 ms
203,432 KB |
testcase_27 | AC | 1,312 ms
198,980 KB |
testcase_28 | AC | 287 ms
109,952 KB |
testcase_29 | AC | 380 ms
110,336 KB |
testcase_30 | AC | 404 ms
109,056 KB |
testcase_31 | AC | 233 ms
109,824 KB |
testcase_32 | AC | 457 ms
109,824 KB |
testcase_33 | AC | 415 ms
109,568 KB |
testcase_34 | AC | 258 ms
109,824 KB |
testcase_35 | AC | 300 ms
110,208 KB |
testcase_36 | AC | 274 ms
109,824 KB |
testcase_37 | AC | 366 ms
109,056 KB |
testcase_38 | AC | 2,114 ms
146,720 KB |
testcase_39 | AC | 1,173 ms
115,200 KB |
testcase_40 | TLE | - |
testcase_41 | AC | 1,574 ms
119,040 KB |
testcase_42 | AC | 2,095 ms
144,904 KB |
testcase_43 | AC | 1,933 ms
129,864 KB |
testcase_44 | AC | 2,352 ms
168,908 KB |
testcase_45 | AC | 2,294 ms
162,604 KB |
testcase_46 | AC | 1,984 ms
138,904 KB |
testcase_47 | AC | 2,203 ms
154,916 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)