結果

問題 No.2242 Cities and Teleporters
ユーザー shobonvipshobonvip
提出日時 2023-03-08 16:57:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 904 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 185,664 KB
最終ジャッジ日時 2023-10-18 06:55:40
合計ジャッジ時間 35,366 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,364 KB
testcase_01 AC 39 ms
53,364 KB
testcase_02 AC 38 ms
53,364 KB
testcase_03 AC 38 ms
53,364 KB
testcase_04 WA -
testcase_05 AC 1,370 ms
164,600 KB
testcase_06 AC 1,603 ms
183,720 KB
testcase_07 AC 1,602 ms
184,920 KB
testcase_08 AC 1,740 ms
184,824 KB
testcase_09 AC 1,783 ms
184,820 KB
testcase_10 AC 971 ms
185,664 KB
testcase_11 AC 1,270 ms
184,968 KB
testcase_12 AC 1,307 ms
185,104 KB
testcase_13 AC 1,318 ms
185,492 KB
testcase_14 AC 1,603 ms
185,344 KB
testcase_15 AC 1,321 ms
185,480 KB
testcase_16 AC 1,434 ms
184,840 KB
testcase_17 AC 1,943 ms
184,652 KB
testcase_18 AC 1,294 ms
184,124 KB
testcase_19 AC 1,440 ms
184,432 KB
testcase_20 AC 1,438 ms
182,160 KB
testcase_21 AC 1,245 ms
182,908 KB
testcase_22 AC 1,511 ms
182,220 KB
testcase_23 AC 1,384 ms
184,824 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] = max(dp[i][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