結果

問題 No.2242 Cities and Teleporters
ユーザー titiatitia
提出日時 2023-03-11 02:23:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,237 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 251,372 KB
最終ジャッジ日時 2023-10-18 09:36:43
合計ジャッジ時間 18,054 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,028 KB
testcase_01 AC 36 ms
52,008 KB
testcase_02 AC 37 ms
52,016 KB
testcase_03 AC 38 ms
52,016 KB
testcase_04 AC 38 ms
52,104 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 752 ms
244,316 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 772 ms
250,952 KB
testcase_23 AC 744 ms
245,664 KB
testcase_24 AC 753 ms
245,792 KB
testcase_25 AC 772 ms
246,348 KB
権限があれば一括ダウンロードができます

ソースコード

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+[0]
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=[0]*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 = [0]*len(X)
    for k in range(len(X)):
        B[k]=DOUBLING[-1][k]
    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-1))
                    break
        else:
            ANS[tests]=-1
            break
    else:
        ANS[tests]=score+1

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