結果

問題 No.2242 Cities and Teleporters
ユーザー titiatitia
提出日時 2023-03-11 02:05:42
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,264 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 81,888 KB
実行使用メモリ 128,884 KB
最終ジャッジ日時 2023-10-18 09:35:32
合計ジャッジ時間 6,397 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
128,884 KB
testcase_01 AC 37 ms
53,580 KB
testcase_02 AC 37 ms
53,580 KB
testcase_03 AC 37 ms
53,580 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
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()))

X=H+T
X=sorted(set(X))
D={X[i]:i for i in range(len(X))}

for i in range(N):
    H[i]=D[H[i]]
    T[i]=D[T[i]]

DOUBLING=[-1]*len(X)

for i in range(N):
    DOUBLING[H[i]]=max(DOUBLING[H[i]],T[i])

for i in range(1,len(X)):
    DOUBLING[i]=max(DOUBLING[i],DOUBLING[i-1])

DOUBLING=[DOUBLING]

for i in range(30):
    j = 1<<i
    B = []
    for k in range(len(DOUBLING[-1])-j):
        B.append(max(DOUBLING[-1][k], DOUBLING[-1][k+j]))
    DOUBLING.append(B)

Q=int(input())
ANS=[-1]*Q
for tests in range(Q):
    x,y=map(int,input().split())
    x-=1
    y-=1

    start=T[x]
    to=H[y]

    if to<=start:
        ANS[tests]=1
        continue

    now=start
    score=0

    while now!=to:

        for i in range(30):
            if now<len(DOUBLING[i]) and DOUBLING[i][now]>=to:
                if i==0:
                    now=to
                    score+=1
                    break
                else:
                    now=DOUBLING[i-1][now]
                    score+=(1<<i)
                    break
        else:
            ANS[tests]=-1
            break
    else:
        ANS[tests]=score+1

print("\n".join(map(str,ANS)))
0