結果

問題 No.2002 Range Swap Query
ユーザー otoshigootoshigo
提出日時 2023-12-09 18:33:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,236 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 87,624 KB
実行使用メモリ 27,300 KB
最終ジャッジ日時 2023-12-09 18:33:26
合計ジャッジ時間 7,376 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 RE -
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 RE -
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 263 ms
27,300 KB
testcase_13 AC 255 ms
27,300 KB
testcase_14 AC 247 ms
27,300 KB
testcase_15 AC 268 ms
26,532 KB
testcase_16 AC 123 ms
22,436 KB
testcase_17 AC 251 ms
27,300 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 76 ms
11,904 KB
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    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<vector<pair<int,int>>>vp(K);
    vector<vector<int>>vs(K);
    for(int i=0;i<Q;i++){
        int l,r,x;
        cin>>l>>r>>x;
        l--;
        r--;
        x--;
        vp[r].push_back(make_pair(x,i));
        vs[l].push_back(i);
    }
    vector<int>P(N),at(N),V(N,-1);
    for(int i=0;i<N;i++){
        P[i]=i;
        at[i]=i;
    }
    vector<int>ans(Q);
    for(int i=K-1;i>=0;i--){
        for(auto[x,q]:vp[i]){
            V[q]=P[x];
        }
        swap(P[A[i]],P[B[i]]);
        swap(at[P[A[i]]],at[P[B[i]]]);
        for(auto q:vs[i]){
            ans[q]=at[V[q]];
        }
    }
    for(int i=0;i<Q;i++)cout<<ans[i]+1<<"\n";
}
0