結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,608 KB
testcase_01 AC 37 ms
55,608 KB
testcase_02 AC 41 ms
55,608 KB
testcase_03 AC 39 ms
55,608 KB
testcase_04 AC 40 ms
55,608 KB
testcase_05 AC 2,491 ms
173,584 KB
testcase_06 AC 1,629 ms
181,776 KB
testcase_07 AC 2,459 ms
181,828 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 AC 1,674 ms
183,852 KB
testcase_11 WA -
testcase_12 AC 1,123 ms
155,920 KB
testcase_13 AC 1,568 ms
155,668 KB
testcase_14 AC 1,818 ms
158,744 KB
testcase_15 AC 1,464 ms
156,052 KB
testcase_16 AC 2,143 ms
158,996 KB
testcase_17 AC 2,547 ms
165,876 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1,417 ms
152,232 KB
testcase_21 AC 1,280 ms
153,236 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1,056 ms
155,412 KB
testcase_25 AC 1,098 ms
155,672 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 = 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 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