結果
問題 | No.2002 Range Swap Query |
ユーザー |
|
提出日時 | 2023-12-09 18:33:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,236 bytes |
コンパイル時間 | 1,000 ms |
コンパイル使用メモリ | 83,104 KB |
最終ジャッジ日時 | 2025-02-18 09:50:03 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 RE * 1 |
other | AC * 11 RE * 9 |
ソースコード
#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"; }