結果

問題 No.2002 Range Swap Query
ユーザー souta-1326souta-1326
提出日時 2022-04-22 23:44:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 273 ms / 2,000 ms
コード長 784 bytes
コンパイル時間 2,692 ms
コンパイル使用メモリ 203,276 KB
実行使用メモリ 28,232 KB
最終ジャッジ日時 2023-09-09 21:47:54
合計ジャッジ時間 5,883 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,356 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,360 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 2 ms
4,356 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 4 ms
4,360 KB
testcase_09 AC 5 ms
4,356 KB
testcase_10 AC 2 ms
4,356 KB
testcase_11 AC 4 ms
4,352 KB
testcase_12 AC 263 ms
28,232 KB
testcase_13 AC 273 ms
28,200 KB
testcase_14 AC 268 ms
28,112 KB
testcase_15 AC 254 ms
27,128 KB
testcase_16 AC 116 ms
22,728 KB
testcase_17 AC 268 ms
28,092 KB
testcase_18 AC 104 ms
10,660 KB
testcase_19 AC 213 ms
24,940 KB
testcase_20 AC 72 ms
12,200 KB
testcase_21 AC 62 ms
9,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  int N,K,Q;cin >> N >> K >> Q;
  vector<int> A(K),B(K);
  for(int i=0;i<K;i++){
    cin >> A[i] >> B[i];A[i]--;B[i]--;
  }
  vector<int> L(Q),R(Q),X(Q);
  vector<vector<int>> R_E(K),L_E(K);
  for(int i=0;i<Q;i++){
    cin >> L[i] >> R[i] >> X[i];L[i]--;R[i]--;X[i]--;
    R_E[R[i]].emplace_back(i);
    L_E[L[i]].emplace_back(i);
  }
  vector<int> P(N),where_P(N);
  for(int i=0;i<N;i++) P[i] = where_P[i] = i;
  vector<int> ans(Q),target(Q);
  for(int i=K-1;i>=0;i--){
    for(int id:R_E[i]) target[id] = P[X[id]];
    swap(P[A[i]],P[B[i]]);swap(where_P[P[A[i]]],where_P[P[B[i]]]);
    for(int id:L_E[i]) ans[id] = where_P[target[id]]+1;
  }
  for(int num:ans) cout << num << "\n";
}
0