結果

問題 No.2242 Cities and Teleporters
ユーザー rin204rin204
提出日時 2024-04-28 14:55:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 902 ms / 3,000 ms
コード長 934 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 245,960 KB
最終ジャッジ日時 2024-04-28 14:55:33
合計ジャッジ時間 21,313 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,608 KB
testcase_01 AC 37 ms
52,224 KB
testcase_02 AC 39 ms
51,840 KB
testcase_03 AC 38 ms
52,352 KB
testcase_04 AC 40 ms
52,352 KB
testcase_05 AC 598 ms
218,912 KB
testcase_06 AC 571 ms
202,944 KB
testcase_07 AC 606 ms
195,012 KB
testcase_08 AC 801 ms
198,220 KB
testcase_09 AC 630 ms
195,148 KB
testcase_10 AC 650 ms
232,008 KB
testcase_11 AC 812 ms
234,576 KB
testcase_12 AC 722 ms
234,048 KB
testcase_13 AC 768 ms
231,748 KB
testcase_14 AC 789 ms
234,696 KB
testcase_15 AC 688 ms
234,952 KB
testcase_16 AC 887 ms
235,072 KB
testcase_17 AC 902 ms
230,856 KB
testcase_18 AC 713 ms
236,812 KB
testcase_19 AC 798 ms
238,444 KB
testcase_20 AC 698 ms
234,980 KB
testcase_21 AC 683 ms
245,960 KB
testcase_22 AC 899 ms
245,508 KB
testcase_23 AC 860 ms
231,500 KB
testcase_24 AC 830 ms
231,536 KB
testcase_25 AC 865 ms
231,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.readline

n = int(input())
H = list(map(int, input().split()))
T = list(map(int, input().split()))
X = H + T
X = sorted(set(X))
dic = {X[i]: i for i in range(len(X))}
H = [dic[h] for h in H]
T = [dic[t] for t in T]
le = len(X)

m = 20
nex = [[i for i in range(le)] for _ in range(m)]
for h, t in zip(H, T):
    nex[0][h] = max(nex[0][h], t)

for i in range(1, le):
    nex[0][i] = max(nex[0][i], nex[0][i - 1])

for i in range(1, m):
    for j in range(le):
        nex[i][j] = nex[i - 1][nex[i - 1][j]]

Q = int(input())
for _ in range(Q):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if T[a] >= H[b]:
        print(1)
        continue
    ans = 1
    t = T[a]
    for i in range(m - 1, -1, -1):
        nt = nex[i][t]
        if nt < H[b]:
            t = nt
            ans += 1 << i
    ans += 1
    nt = nex[0][t]

    if nt >= H[b]:
        print(ans)
    else:
        print(-1)
0