結果

問題 No.2002 Range Swap Query
ユーザー 👑 rin204rin204
提出日時 2022-09-19 01:53:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 726 ms / 2,000 ms
コード長 744 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 87,300 KB
実行使用メモリ 137,120 KB
最終ジャッジ日時 2023-08-23 18:32:09
合計ジャッジ時間 8,840 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,284 KB
testcase_01 AC 69 ms
71,184 KB
testcase_02 AC 70 ms
71,452 KB
testcase_03 AC 68 ms
71,504 KB
testcase_04 AC 68 ms
71,520 KB
testcase_05 AC 68 ms
71,304 KB
testcase_06 AC 69 ms
71,308 KB
testcase_07 AC 67 ms
71,132 KB
testcase_08 AC 137 ms
78,488 KB
testcase_09 AC 106 ms
77,800 KB
testcase_10 AC 78 ms
75,124 KB
testcase_11 AC 134 ms
78,652 KB
testcase_12 AC 709 ms
136,856 KB
testcase_13 AC 726 ms
137,120 KB
testcase_14 AC 715 ms
137,012 KB
testcase_15 AC 685 ms
135,740 KB
testcase_16 AC 449 ms
132,876 KB
testcase_17 AC 685 ms
136,992 KB
testcase_18 AC 365 ms
100,448 KB
testcase_19 AC 622 ms
129,944 KB
testcase_20 AC 253 ms
108,632 KB
testcase_21 AC 229 ms
101,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k, Q_ = map(int, input().split())
ab = []
P = list(range(n))
for _ in range(k):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ab.append((a, b))
    P[a], P[b] = P[b], P[a]

X = [0] * Q_
L = [[] for _ in range(k)]
R = [[] for _ in range(k)]
for i in range(Q_):
    l, r, x = map(int, input().split())
    l -= 1
    r -= 1
    x -= 1
    X[i] = x
    L[l].append(i)
    R[r].append(i)

Q = [0] * n
for i, p in enumerate(P):
    Q[p] = i

ans = [0] * Q_
for i in range(k - 1, -1, -1):
    for j in R[i]:
        x = X[j]
        X[j] = P[x]

    a, b = ab[i]
    P[a], P[b] = P[b], P[a]
    a = P[a]
    b = P[b]
    Q[a], Q[b] = Q[b], Q[a]

    for j in L[i]:
        x = X[j]
        ans[j] = Q[x] + 1

print(*ans, sep="\n")
0