結果

問題 No.2242 Cities and Teleporters
ユーザー mkawa2mkawa2
提出日時 2023-03-10 23:39:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,696 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 81,724 KB
実行使用メモリ 200,240 KB
最終ジャッジ日時 2023-10-18 09:15:49
合計ジャッジ時間 27,386 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,368 KB
testcase_01 AC 40 ms
53,368 KB
testcase_02 AC 39 ms
53,368 KB
testcase_03 AC 39 ms
53,368 KB
testcase_04 AC 38 ms
53,368 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1,159 ms
187,016 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1,070 ms
189,744 KB
testcase_19 AC 1,223 ms
193,144 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1,166 ms
199,232 KB
testcase_23 AC 1,202 ms
184,940 KB
testcase_24 AC 1,105 ms
187,032 KB
testcase_25 AC 1,008 ms
184,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

from bisect import bisect_left

n = II()
hh = LI()
tt = LI()

vv = sorted(set(tt))
vtoi = {v: i for i, v in enumerate(vv)}
to = [0]*len(vv)
uh = sorted(enumerate(hh), key=lambda x: x[1])
vi = 0
mx = -1
for u, h in uh:
    while vi < len(vv) and h > vv[vi]:
        if mx != -1:
            to[vi] = vtoi[mx]
        vi += 1
    mx = max(mx, tt[u])
# pDB(vv)
# pDB(to)

log = n.bit_length()
db = [[inf]*len(vv) for _ in range(log)]
db[0] = to
for i in range(log-1):
    for j in range(len(vv)):
        nj = db[i][j]
        if nj == inf: continue
        db[i+1][j] = db[i][nj]

for _ in range(II()):
    u, v = LI1()
    h = hh[u]
    g = hh[v]
    i = vtoi[tt[u]]
    j = bisect_left(vv, g)
    if j <= i:
        print(1)
        continue

    ans = 2
    for lv in range(log)[::-1]:
        if db[lv][i] == inf: continue
        if db[lv][i] < j:
            i = db[lv][i]
            ans += 1 << lv
    if db[0][i]<j:
        print(-1)
    else:
        print(ans)

0