結果

問題 No.2242 Cities and Teleporters
ユーザー chineristACchineristAC
提出日時 2023-03-10 22:56:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,293 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 81,460 KB
実行使用メモリ 266,512 KB
最終ジャッジ日時 2023-10-18 08:38:56
合計ジャッジ時間 33,041 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
56,064 KB
testcase_01 AC 47 ms
56,064 KB
testcase_02 AC 47 ms
56,064 KB
testcase_03 AC 48 ms
56,064 KB
testcase_04 AC 47 ms
56,064 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1,454 ms
264,852 KB
testcase_12 AC 1,527 ms
263,872 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1,248 ms
265,228 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1,248 ms
265,592 KB
testcase_23 AC 1,310 ms
265,048 KB
testcase_24 AC 1,286 ms
265,216 KB
testcase_25 AC 1,393 ms
265,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

N = int(input())
H = list(map(int,input().split()))
T = list(map(int,input().split()))

val_set = set(H) | set(T)
comp = {e:i for i,e in enumerate(sorted(val_set))}
M = len(comp)
H = [comp[h] for h in H]
T = [comp[t] for t in T]

K = 19
highest = [[0]*M for i in range(K)]
for i in range(N):
    highest[0][H[i]] = max(highest[0][H[i]],T[i])

for k in range(1,K+1):
    cum_max = [0] * M
    for i in range(M):
        cum_max[i] = highest[k-1][i]
    for i in range(1,M):
        cum_max[i] = max(cum_max[i],cum_max[i-1])
    
    
    highest[k-1] = cum_max

    if k == K:
        continue
    
    for i in range(N):
        highest[k][H[i]] = max(highest[k][H[i]],cum_max[highest[k-1][T[i]]])



for _ in range(int(input())):
    a,b = map(int,input().split())
    a,b = a-1,b-1

    if a == b:
        print(0)
        continue

    a = T[a]
    if a >= H[b]:
        print(1)
        continue
    
    if highest[K-1][a] < H[b]:
        print(-1)
        continue

    res = 1
    for k in range(K)[::-1]:
        if highest[k][a] < H[b]:
            res += 1<<k
            a = highest[k][a]
    
    print(res+1)
0