結果

問題 No.2242 Cities and Teleporters
ユーザー shobonvipshobonvip
提出日時 2023-03-09 13:12:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,886 ms / 3,000 ms
コード長 851 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 82,644 KB
実行使用メモリ 139,656 KB
最終ジャッジ日時 2024-09-18 03:30:35
合計ジャッジ時間 34,897 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,512 KB
testcase_01 AC 35 ms
52,820 KB
testcase_02 AC 35 ms
53,544 KB
testcase_03 AC 37 ms
54,216 KB
testcase_04 AC 36 ms
54,016 KB
testcase_05 AC 1,616 ms
127,536 KB
testcase_06 AC 1,064 ms
139,656 KB
testcase_07 AC 1,601 ms
139,068 KB
testcase_08 AC 1,777 ms
138,676 KB
testcase_09 AC 1,538 ms
138,808 KB
testcase_10 AC 1,254 ms
138,684 KB
testcase_11 AC 1,403 ms
138,816 KB
testcase_12 AC 1,473 ms
139,452 KB
testcase_13 AC 1,383 ms
139,056 KB
testcase_14 AC 1,526 ms
139,440 KB
testcase_15 AC 1,515 ms
139,192 KB
testcase_16 AC 1,707 ms
139,056 KB
testcase_17 AC 1,886 ms
138,940 KB
testcase_18 AC 1,459 ms
139,636 KB
testcase_19 AC 1,423 ms
139,436 KB
testcase_20 AC 1,454 ms
138,604 KB
testcase_21 AC 1,491 ms
138,632 KB
testcase_22 AC 1,510 ms
138,952 KB
testcase_23 AC 1,457 ms
138,972 KB
testcase_24 AC 1,591 ms
138,940 KB
testcase_25 AC 1,660 ms
139,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

n = int(input())
h = list(map(int,input().split()))
t = list(map(int,input().split()))
g = [(h[i], -t[i]) for i in range(n)]
g.sort()

hs = [g[i][0] for i in range(n)]
ts = [-g[i][1] for i in range(n)]
dp = [[0] * n for i in range(19)]

tmp = 0
for i in range(n):
	tmp = max(tmp, ts[i])
	dp[0][i] = max(i, bisect.bisect_right(hs, tmp) - 1)

for i in range(18):
	for j in range(n):
		if dp[i][j] >= 0:
			dp[i+1][j] = max(dp[i][j], dp[i][dp[i][j]])
		else:
			dp[i+1][j] = -1

q = int(input())
for i in range(q):
	a, b = map(int,input().split())
	a -= 1
	b -= 1
	f = 1
	r = bisect.bisect_right(hs, t[a]) - 1
	if r == -1:
		print(-1)
		continue
	if hs[r] >= h[b]:
		print(1)
		continue
	for j in range(18,-1,-1):
		if dp[j][r] >= 0 and hs[dp[j][r]] < h[b]:
			f += 2 ** j
			r = dp[j][r]
	if f >= n + 1:
		print(-1)
	else:
		print(f + 1)
0