結果
| 問題 |
No.2242 Cities and Teleporters
|
| コンテスト | |
| ユーザー |
rlangevin
|
| 提出日時 | 2023-11-26 12:23:19 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,746 ms / 3,000 ms |
| コード長 | 1,157 bytes |
| コンパイル時間 | 577 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 177,128 KB |
| 最終ジャッジ日時 | 2024-09-26 11:38:43 |
| 合計ジャッジ時間 | 30,751 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
import sys
input = sys.stdin.readline
N = int(input())
H = list(map(int, input().split()))
T = list(map(int, input().split()))
HT = []
for i in range(N):
HT.append((-T[i], H[i], i))
HT.sort()
M = 18
dp = [[-1] * N for i in range(M)]
from bisect import *
from collections import *
inf = 10 ** 18
minv = defaultdict(lambda : inf)
L = [-inf]
for t, h, i in HT:
h = -h
ind = bisect_left(L, t)
if ind != len(L):
dp[0][i] = minv[L[ind]]
if h > L[-1]:
L.append(h)
minv[h] = i
for i in range(1, M):
for j in range(N):
if dp[i-1][j] == -1:
continue
dp[i][j] = dp[i-1][dp[i-1][j]]
Q = int(input())
for _ in range(Q):
A, B = map(int, input().split())
A, B = A - 1, B - 1
if H[B] <= T[A]:
print(1)
continue
now = A
ans = 1
for i in range(M-1, -1, -1):
nex = dp[i][now]
if nex == -1:
continue
if T[nex] < H[B]:
ans += 1 << i
now = nex
now = dp[0][now]
if now == -1:
print(-1)
elif T[now] >= H[B]:
print(ans + 1)
else:
print(-1)
rlangevin