結果
問題 | No.2242 Cities and Teleporters |
ユーザー | mkawa2 |
提出日時 | 2023-03-10 23:39:01 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,696 bytes |
コンパイル時間 | 297 ms |
コンパイル使用メモリ | 82,472 KB |
実行使用メモリ | 200,904 KB |
最終ジャッジ日時 | 2024-09-18 05:43:53 |
合計ジャッジ時間 | 26,868 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,608 KB |
testcase_01 | AC | 40 ms
52,736 KB |
testcase_02 | AC | 39 ms
52,480 KB |
testcase_03 | AC | 39 ms
52,480 KB |
testcase_04 | AC | 40 ms
52,480 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 1,118 ms
187,204 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 1,077 ms
190,580 KB |
testcase_19 | AC | 1,178 ms
193,516 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 1,158 ms
199,972 KB |
testcase_23 | AC | 1,195 ms
185,284 KB |
testcase_24 | AC | 1,141 ms
187,328 KB |
testcase_25 | AC | 1,021 ms
185,140 KB |
ソースコード
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)