結果
問題 | No.2242 Cities and Teleporters |
ユーザー | mkawa2 |
提出日時 | 2023-03-11 00:01:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,354 ms / 3,000 ms |
コード長 | 1,768 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 200,512 KB |
最終ジャッジ日時 | 2024-09-18 05:47:42 |
合計ジャッジ時間 | 26,161 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,992 KB |
testcase_01 | AC | 40 ms
52,736 KB |
testcase_02 | AC | 40 ms
52,224 KB |
testcase_03 | AC | 41 ms
52,608 KB |
testcase_04 | AC | 40 ms
52,352 KB |
testcase_05 | AC | 1,101 ms
182,424 KB |
testcase_06 | AC | 894 ms
193,984 KB |
testcase_07 | AC | 1,168 ms
184,896 KB |
testcase_08 | AC | 1,354 ms
187,568 KB |
testcase_09 | AC | 1,162 ms
185,052 KB |
testcase_10 | AC | 749 ms
185,904 KB |
testcase_11 | AC | 1,036 ms
187,320 KB |
testcase_12 | AC | 1,070 ms
185,208 KB |
testcase_13 | AC | 1,075 ms
186,920 KB |
testcase_14 | AC | 1,150 ms
187,716 KB |
testcase_15 | AC | 1,077 ms
187,452 KB |
testcase_16 | AC | 1,204 ms
187,316 KB |
testcase_17 | AC | 1,252 ms
186,820 KB |
testcase_18 | AC | 1,061 ms
190,096 KB |
testcase_19 | AC | 1,170 ms
193,124 KB |
testcase_20 | AC | 1,097 ms
199,816 KB |
testcase_21 | AC | 1,056 ms
200,512 KB |
testcase_22 | AC | 1,148 ms
199,232 KB |
testcase_23 | AC | 1,164 ms
184,772 KB |
testcase_24 | AC | 1,074 ms
184,880 KB |
testcase_25 | AC | 948 ms
185,216 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]) while vi < len(vv): if mx != -1: to[vi] = vtoi[mx] vi += 1 # pDB(vv) # pDB(to) log = n.bit_length() db = [[-1]*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 == -1: 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] == -1: continue if db[lv][i] < j: i = db[lv][i] ans += 1 << lv if db[0][i]<j: print(-1) else: print(ans)