結果
| 問題 |
No.2002 Range Swap Query
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2022-07-08 21:41:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 262 ms / 2,000 ms |
| コード長 | 1,353 bytes |
| コンパイル時間 | 2,161 ms |
| コンパイル使用メモリ | 199,920 KB |
| 最終ジャッジ日時 | 2025-01-30 05:19:08 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#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";
}
Rubikun