結果
| 問題 |
No.2242 Cities and Teleporters
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-10 22:56:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,293 bytes |
| コンパイル時間 | 315 ms |
| コンパイル使用メモリ | 82,396 KB |
| 実行使用メモリ | 266,528 KB |
| 最終ジャッジ日時 | 2024-09-18 05:05:54 |
| 合計ジャッジ時間 | 28,679 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 14 |
ソースコード
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)