結果

問題 No.2242 Cities and Teleporters
ユーザー 👑 rin204rin204
提出日時 2024-04-28 14:55:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,582 ms / 3,000 ms
コード長 894 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 247,684 KB
最終ジャッジ日時 2024-04-28 14:56:32
合計ジャッジ時間 30,451 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,224 KB
testcase_01 AC 42 ms
52,352 KB
testcase_02 AC 41 ms
52,096 KB
testcase_03 AC 41 ms
52,352 KB
testcase_04 AC 42 ms
52,096 KB
testcase_05 AC 1,109 ms
220,188 KB
testcase_06 AC 1,026 ms
204,924 KB
testcase_07 AC 1,107 ms
197,368 KB
testcase_08 AC 1,378 ms
200,396 KB
testcase_09 AC 1,248 ms
197,192 KB
testcase_10 AC 1,168 ms
234,104 KB
testcase_11 AC 1,325 ms
236,364 KB
testcase_12 AC 1,180 ms
235,712 KB
testcase_13 AC 1,379 ms
233,848 KB
testcase_14 AC 1,337 ms
236,492 KB
testcase_15 AC 1,216 ms
237,056 KB
testcase_16 AC 1,474 ms
236,616 KB
testcase_17 AC 1,582 ms
232,644 KB
testcase_18 AC 1,230 ms
238,616 KB
testcase_19 AC 1,324 ms
240,612 KB
testcase_20 AC 1,200 ms
226,840 KB
testcase_21 AC 1,206 ms
247,624 KB
testcase_22 AC 1,320 ms
247,684 KB
testcase_23 AC 1,387 ms
233,680 KB
testcase_24 AC 1,411 ms
233,672 KB
testcase_25 AC 1,379 ms
233,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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