結果

問題 No.2002 Range Swap Query
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-07-08 05:58:26
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 434 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 3,125 ms
コンパイル使用メモリ 256,396 KB
実行使用メモリ 25,536 KB
最終ジャッジ日時 2023-09-29 07:31:36
合計ジャッジ時間 8,655 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 431 ms
25,516 KB
testcase_13 AC 434 ms
25,436 KB
testcase_14 AC 433 ms
25,336 KB
testcase_15 AC 419 ms
24,424 KB
testcase_16 AC 290 ms
21,308 KB
testcase_17 AC 434 ms
25,536 KB
testcase_18 AC 203 ms
8,580 KB
testcase_19 AC 338 ms
22,244 KB
testcase_20 AC 151 ms
9,856 KB
testcase_21 AC 118 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define db double
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
	int n,k,q;cin>>n>>k>>q;
	vc<int>a(k),b(k); rep(i,k)cin>>a[i]>>b[i]; rep(i,k)a[i]--,b[i]--;
	vc<int>v(n); rep(i,n)v[i]=i;
	rep(i,k)swap(v[a[i]],v[b[i]]);
	vc<int>rv(n); rep(i,n)rv[v[i]]=i;
	vc rs(k,vc<pp>(0)); vc ls(k,vc<int>(0));
	vc<int>ans(q,-1);
	rep(i,q){
		int l,r,x;cin>>l>>r>>x;
		l--; r--; x--;
		rs[r].pb({i,x}); ls[l].pb(i);
	}
	for(int i=k-1;i>=0;i--){
		for(auto [qi,x]:rs[i])ans[qi]=v[x];
		swap(v[a[i]],v[b[i]]); swap(rv[v[a[i]]],rv[v[b[i]]]);
		for(auto  qi:ls[i])ans[qi]=rv[ans[qi]];
	}
	rep(i,q)cout<<ans[i]+1<<"\n";
}
0