結果

問題 No.2242 Cities and Teleporters
ユーザー gew1fw
提出日時 2025-06-12 15:07:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,158 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 194,472 KB
最終ジャッジ日時 2025-06-12 15:08:40
合計ジャッジ時間 15,587 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    H = list(map(int, input[ptr:ptr+N]))
    ptr += N
    T = list(map(int, input[ptr:ptr+N]))
    ptr += N
    Q = int(input[ptr])
    ptr += 1
    queries = []
    for _ in range(Q):
        A = int(input[ptr]) - 1
        B = int(input[ptr+1]) - 1
        queries.append((A, B))
        ptr += 2

    # Preprocess
    sorted_HT = sorted(zip(H, T), key=lambda x: x[0])
    sorted_H = [x[0] for x in sorted_HT]
    sorted_T = [x[1] for x in sorted_HT]
    max_T = [0] * N
    max_T[0] = sorted_T[0]
    for i in range(1, N):
        max_T[i] = max(max_T[i-1], sorted_T[i])

    # Process each query
    for A, B in queries:
        if H[B] <= T[A]:
            print(1)
        else:
            x = T[A]
            pos = bisect.bisect_right(sorted_H, x) - 1
            if pos >= 0:
                current_max = max_T[pos]
                if current_max >= H[B]:
                    print(2)
                else:
                    print(-1)
            else:
                print(-1)

if __name__ == "__main__":
    main()
0