結果

問題 No.2002 Range Swap Query
ユーザー 👑 kmjpkmjp
提出日時 2022-07-08 23:12:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 587 ms / 2,000 ms
コード長 1,531 bytes
コンパイル時間 2,022 ms
コンパイル使用メモリ 207,228 KB
実行使用メモリ 49,488 KB
最終ジャッジ日時 2023-08-27 23:02:50
合計ジャッジ時間 9,189 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
28,620 KB
testcase_01 AC 8 ms
28,644 KB
testcase_02 AC 9 ms
28,592 KB
testcase_03 AC 8 ms
28,624 KB
testcase_04 AC 8 ms
28,620 KB
testcase_05 AC 8 ms
28,596 KB
testcase_06 AC 8 ms
28,624 KB
testcase_07 AC 9 ms
28,788 KB
testcase_08 AC 16 ms
28,892 KB
testcase_09 AC 23 ms
28,940 KB
testcase_10 AC 10 ms
28,628 KB
testcase_11 AC 16 ms
28,860 KB
testcase_12 AC 581 ms
49,480 KB
testcase_13 AC 587 ms
49,488 KB
testcase_14 AC 579 ms
49,276 KB
testcase_15 AC 560 ms
48,828 KB
testcase_16 AC 506 ms
48,108 KB
testcase_17 AC 449 ms
47,040 KB
testcase_18 AC 332 ms
31,764 KB
testcase_19 AC 418 ms
38,696 KB
testcase_20 AC 344 ms
42,548 KB
testcase_21 AC 307 ms
30,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


int N,K,Q;
int A[202020],B[202020];
vector<pair<int,int>> pos[404040];
int P[404040];
int L[404040],R[404040],X[404040];
vector<int> ev[404040];
int ret[404040];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K>>Q;
	FOR(i,N) {
		pos[i]={{0,i}};
		P[i]=i;
	}
	
	for(i=1;i<=K;i++) {
		cin>>A[i]>>B[i];
		A[i]--;
		B[i]--;
		swap(P[A[i]],P[B[i]]);
		pos[P[A[i]]].push_back({i,A[i]});
		pos[P[B[i]]].push_back({i,B[i]});
	}
	FOR(i,Q) {
		cin>>L[i]>>R[i]>>X[i];
		X[i]--;
		ev[R[i]].push_back(i);
	}
	FOR(i,N) P[i]=i;
	for(i=1;i<=K;i++) {
		swap(P[A[i]],P[B[i]]);
		FORR(e,ev[i]) {
			y=P[X[e]];
			auto it=lower_bound(ALL(pos[y]),make_pair(L[e],0));
			it--;
			ret[e]=it->second+1;
		}
	}
	
	FOR(i,Q) cout<<ret[i]<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0