結果

問題 No.2242 Cities and Teleporters
ユーザー shobonvipshobonvip
提出日時 2023-03-09 13:12:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,057 ms / 3,000 ms
コード長 851 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 81,636 KB
実行使用メモリ 139,140 KB
最終ジャッジ日時 2023-10-18 06:57:13
合計ジャッジ時間 39,819 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,472 KB
testcase_01 AC 38 ms
53,472 KB
testcase_02 AC 39 ms
53,472 KB
testcase_03 AC 39 ms
53,472 KB
testcase_04 AC 38 ms
53,472 KB
testcase_05 AC 1,806 ms
127,032 KB
testcase_06 AC 1,255 ms
138,740 KB
testcase_07 AC 1,784 ms
138,476 KB
testcase_08 AC 2,057 ms
138,388 KB
testcase_09 AC 1,855 ms
138,224 KB
testcase_10 AC 1,363 ms
138,468 KB
testcase_11 AC 1,601 ms
138,580 KB
testcase_12 AC 1,630 ms
138,672 KB
testcase_13 AC 1,595 ms
138,488 KB
testcase_14 AC 1,762 ms
138,672 KB
testcase_15 AC 1,730 ms
138,668 KB
testcase_16 AC 1,921 ms
138,456 KB
testcase_17 AC 2,009 ms
138,352 KB
testcase_18 AC 1,603 ms
139,140 KB
testcase_19 AC 1,630 ms
138,728 KB
testcase_20 AC 1,680 ms
138,096 KB
testcase_21 AC 1,529 ms
138,076 KB
testcase_22 AC 1,659 ms
138,340 KB
testcase_23 AC 1,669 ms
138,628 KB
testcase_24 AC 1,672 ms
138,380 KB
testcase_25 AC 1,718 ms
138,712 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