結果
| 問題 |
No.3072 Speedrun Query
|
| コンテスト | |
| ユーザー |
detteiuu
|
| 提出日時 | 2025-03-21 22:13:12 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 526 ms / 2,500 ms |
| コード長 | 1,052 bytes |
| コンパイル時間 | 278 ms |
| コンパイル使用メモリ | 82,844 KB |
| 実行使用メモリ | 169,564 KB |
| 最終ジャッジ日時 | 2025-03-21 22:13:35 |
| 合計ジャッジ時間 | 11,611 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 21 |
ソースコード
N, K1, K2 = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Q = int(input())
query = [list(map(int, input().split())) for _ in range(Q)]
MIN = 10**18
idx = 0
for a in A:
while idx < K2 and B[idx] < a:
idx += 1
if idx == 0:
MIN = min(MIN, B[idx]-a)
elif idx == K2:
MIN = min(MIN, a-B[idx-1])
else:
MIN = min(MIN, B[idx]-a, a-B[idx-1])
idx1, idx2 = 0, 0
F1 = []
F2 = []
for i in range(N):
if idx1 == 0:
F1.append(A[idx1]-(i+1))
elif idx1 == K1:
F1.append((i+1)-A[-1])
else:
F1.append(min(A[idx1]-(i+1), (i+1)-A[idx1-1]))
if idx2 == 0:
F2.append(B[idx2]-(i+1))
elif idx2 == K2:
F2.append((i+1)-B[-1])
else:
F2.append(min(B[idx2]-(i+1), (i+1)-B[idx2-1]))
if idx1 < K1 and A[idx1] == i+1:
idx1 += 1
if idx2 < K2 and B[idx2] == i+1:
idx2 += 1
for s, t in query:
s, t = s-1, t-1
print(min(t-s, F1[s]+F1[t], F2[s]+F2[t], F1[s]+MIN+F2[t], F2[s]+MIN+F1[t]))
detteiuu