結果

問題 No.2242 Cities and Teleporters
ユーザー rlangevinrlangevin
提出日時 2023-11-26 12:23:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,501 ms / 3,000 ms
コード長 1,157 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 175,732 KB
最終ジャッジ日時 2023-11-26 12:23:48
合計ジャッジ時間 26,542 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,604 KB
testcase_01 AC 41 ms
55,604 KB
testcase_02 AC 40 ms
55,604 KB
testcase_03 AC 42 ms
55,604 KB
testcase_04 AC 42 ms
55,604 KB
testcase_05 AC 1,287 ms
166,880 KB
testcase_06 AC 739 ms
175,544 KB
testcase_07 AC 1,273 ms
175,372 KB
testcase_08 AC 1,501 ms
175,004 KB
testcase_09 AC 1,438 ms
175,104 KB
testcase_10 AC 1,020 ms
175,732 KB
testcase_11 AC 1,003 ms
152,576 KB
testcase_12 AC 1,002 ms
152,568 KB
testcase_13 AC 1,065 ms
152,440 KB
testcase_14 AC 1,115 ms
152,444 KB
testcase_15 AC 1,091 ms
152,952 KB
testcase_16 AC 1,171 ms
152,440 KB
testcase_17 AC 1,252 ms
152,700 KB
testcase_18 AC 1,052 ms
151,748 KB
testcase_19 AC 946 ms
158,112 KB
testcase_20 AC 1,018 ms
149,260 KB
testcase_21 AC 1,038 ms
150,264 KB
testcase_22 AC 969 ms
164,116 KB
testcase_23 AC 952 ms
152,700 KB
testcase_24 AC 901 ms
152,316 KB
testcase_25 AC 932 ms
152,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
H = list(map(int, input().split()))
T = list(map(int, input().split()))
HT = []
for i in range(N):
    HT.append((-T[i], H[i], i))
    
HT.sort()
M = 18
dp = [[-1] * N for i in range(M)]

from bisect import *
from collections import *
inf = 10 ** 18
minv = defaultdict(lambda : inf)
L = [-inf]
for t, h, i in HT:
    h = -h
    ind = bisect_left(L, t)
    if ind != len(L):
        dp[0][i] = minv[L[ind]]  
    if h > L[-1]:
        L.append(h)
        minv[h] = i
     
for i in range(1, M):
    for j in range(N):
        if dp[i-1][j] == -1:
            continue
        dp[i][j] = dp[i-1][dp[i-1][j]]
  
Q = int(input())
for _ in range(Q):
    A, B = map(int, input().split())
    A, B = A - 1, B - 1
    if H[B] <= T[A]:
        print(1)
        continue
    now = A
    ans = 1
    for i in range(M-1, -1, -1):
        nex = dp[i][now]
        if nex == -1:
            continue
        if T[nex] < H[B]:
            ans += 1 << i
            now = nex
    now = dp[0][now]
    if now == -1:
        print(-1)
    elif T[now] >= H[B]:
        print(ans + 1)
    else:
        print(-1)
        
0