結果

問題 No.2002 Range Swap Query
ユーザー RubikunRubikun
提出日時 2022-07-08 21:41:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 1,353 bytes
コンパイル時間 1,974 ms
コンパイル使用メモリ 205,636 KB
実行使用メモリ 36,780 KB
最終ジャッジ日時 2023-08-27 21:07:00
合計ジャッジ時間 5,676 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
23,192 KB
testcase_01 AC 8 ms
23,204 KB
testcase_02 AC 7 ms
23,212 KB
testcase_03 AC 7 ms
23,188 KB
testcase_04 AC 8 ms
23,228 KB
testcase_05 AC 8 ms
23,372 KB
testcase_06 AC 8 ms
23,204 KB
testcase_07 AC 8 ms
23,376 KB
testcase_08 AC 10 ms
23,396 KB
testcase_09 AC 10 ms
23,492 KB
testcase_10 AC 8 ms
23,324 KB
testcase_11 AC 10 ms
23,456 KB
testcase_12 AC 197 ms
36,672 KB
testcase_13 AC 189 ms
36,664 KB
testcase_14 AC 192 ms
36,780 KB
testcase_15 AC 182 ms
36,436 KB
testcase_16 AC 117 ms
32,148 KB
testcase_17 AC 186 ms
36,732 KB
testcase_18 AC 96 ms
30,104 KB
testcase_19 AC 159 ms
33,608 KB
testcase_20 AC 76 ms
31,456 KB
testcase_21 AC 66 ms
28,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=400005,INF=1<<30;

vector<pair<int,int>> inn[MAX],outt[MAX];
int ans[MAX],dic[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K,Q;cin>>N>>K>>Q;
    vector<pair<int,int>> mov(K);
    for(int i=0;i<K;i++){
        cin>>mov[i].fi>>mov[i].se;
        mov[i].fi--;mov[i].se--;
    }
    for(int q=0;q<Q;q++){
        int l,r,x;cin>>l>>r>>x;l--;r--;x--;
        inn[r].push_back(mp(x,q));
        outt[l].push_back(mp(x,q));
    }
    
    vector<int> P(N),pos(N);
    iota(all(P),0);
    iota(all(pos),0);
    
    for(int t=K-1;t>=0;t--){
        for(auto [x,id]:inn[t]){
            dic[id]=P[x];
        }
        int a=mov[t].fi,b=mov[t].se;
        swap(P[a],P[b]);
        swap(pos[P[a]],pos[P[b]]);
        for(auto [x,id]:outt[t]){
            ans[id]=pos[dic[id]];
        }
    }
    
    for(int q=0;q<Q;q++) cout<<ans[q]+1<<"\n";
}
0