結果

問題 No.2242 Cities and Teleporters
ユーザー shobonvipshobonvip
提出日時 2023-03-08 06:46:31
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 889 bytes
コンパイル時間 1,236 ms
コンパイル使用メモリ 81,560 KB
実行使用メモリ 185,412 KB
最終ジャッジ日時 2023-10-18 06:54:18
合計ジャッジ時間 33,993 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,296 KB
testcase_01 AC 39 ms
53,296 KB
testcase_02 AC 38 ms
53,296 KB
testcase_03 AC 38 ms
53,296 KB
testcase_04 WA -
testcase_05 AC 1,390 ms
164,496 KB
testcase_06 AC 1,563 ms
183,648 KB
testcase_07 AC 1,497 ms
184,784 KB
testcase_08 AC 1,701 ms
184,748 KB
testcase_09 AC 1,743 ms
184,748 KB
testcase_10 AC 939 ms
185,256 KB
testcase_11 AC 1,202 ms
184,904 KB
testcase_12 AC 1,226 ms
185,036 KB
testcase_13 AC 1,268 ms
184,856 KB
testcase_14 AC 1,578 ms
185,280 KB
testcase_15 AC 1,282 ms
185,412 KB
testcase_16 AC 1,403 ms
184,760 KB
testcase_17 AC 1,913 ms
184,572 KB
testcase_18 AC 1,264 ms
184,064 KB
testcase_19 AC 1,425 ms
184,364 KB
testcase_20 AC 1,386 ms
182,088 KB
testcase_21 AC 1,182 ms
182,832 KB
testcase_22 AC 1,347 ms
182,136 KB
testcase_23 AC 1,404 ms
184,760 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

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

hs = [g[i] >> 31 for i in range(n)]
ts = [(1 << 30) - (g[i] & ((1 << 31) - 1)) for i in range(n)]
dp = [[0] * n for i in range(30)]

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

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

#print(dp)

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(29,-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