結果

問題 No.2242 Cities and Teleporters
ユーザー rlangevinrlangevin
提出日時 2023-11-26 02:15:53
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,295 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 190,788 KB
最終ジャッジ日時 2023-11-26 02:16:11
合計ジャッジ時間 15,386 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,608 KB
testcase_01 AC 42 ms
55,608 KB
testcase_02 AC 42 ms
55,608 KB
testcase_03 AC 43 ms
55,608 KB
testcase_04 AC 43 ms
55,608 KB
testcase_05 TLE -
testcase_06 AC 2,130 ms
181,908 KB
testcase_07 TLE -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = 20
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]]
        
        
def check(m, A, B):
    now = A
    for i in range(M):
        if (m >> i) & 1:
            now = dp[i][now]
            if now == -1:
                return 2
    return int(T[now] >= H[B])  
  
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
    yes = N + 1
    no = 0
    while yes - no != 1:
        mid = (yes + no)//2
        flag = check(mid, A, B)
        if flag:
            yes = mid
        else:
            no = mid
            
    if flag == 2:
        print(-1)
    else:
        print(yes + 1)
0