Submission #63316188


Source Code Expand

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

int n, q;
std::vector<int> nestToIdx, lblToIdx, idxToLbl;
void solve(){
	cin >> n >> q;
	nestToIdx.resize(n+1);
	lblToIdx.resize(n+1);
	idxToLbl.resize(n+1);
	for(int i = 1; i <= n; i++){
		lblToIdx[i] = i;
		idxToLbl[i] = i;
		nestToIdx[i] = i;
	}
	for(int i = 0; i < q; i++){
		int type, a, b;
		cin >> type;
		if(type == 1){
			cin >> a >> b;
			nestToIdx[a] = lblToIdx[b];
		}
		else if(type == 2){
			cin >> a >> b;
			// idxToLbl[lblToIdx[a]] = b;
			// idxToLbl[lblToIdx[b]] = a;
			// swap(lblToIdx[a], lblToIdx[b]);
			 //5
			int lb1 = a;
			int lb2 = b;
			int idx1 = lblToIdx[lb1];
			int idx2 = lblToIdx[lb2];
			idxToLbl[idx1] = b;
			idxToLbl[idx2] = a;
			swap(lblToIdx[lb1], lblToIdx[lb2]);
			//set lb2's idx to idx1
			//set lb1's idx to idx2;
			//set idx1's lb to lb2
			//set idx2's lb to lb1

		}
		else{
			cin >> a;
		cout<< idxToLbl[nestToIdx[a]] << "\n";

		
		}
	}
}
 
int main(){
	int t = 1;
	//cin >> t;
	
	while(t--){
		solve();
	}
 
	return 0;
}

Submission Info

Submission Time
Task D - Pigeon Swap
User sasmitBiceps
Language C++ 17 (gcc 12.2)
Score 350
Code Size 1108 Byte
Status AC
Exec Time 388 ms
Memory 14960 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 31
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3488 KiB
00_sample_01.txt AC 1 ms 3576 KiB
00_sample_02.txt AC 1 ms 3472 KiB
01_random_03.txt AC 232 ms 14804 KiB
01_random_04.txt AC 234 ms 14792 KiB
01_random_05.txt AC 233 ms 14792 KiB
01_random_06.txt AC 234 ms 14784 KiB
01_random_07.txt AC 12 ms 10824 KiB
01_random_08.txt AC 134 ms 10840 KiB
01_random_09.txt AC 133 ms 14860 KiB
01_random_10.txt AC 174 ms 14960 KiB
01_random_11.txt AC 237 ms 14768 KiB
01_random_12.txt AC 133 ms 14772 KiB
01_random_13.txt AC 323 ms 14728 KiB
01_random_14.txt AC 211 ms 14712 KiB
01_random_15.txt AC 137 ms 14860 KiB
01_random_16.txt AC 375 ms 14856 KiB
01_random_17.txt AC 310 ms 14712 KiB
01_random_18.txt AC 134 ms 14960 KiB
01_random_19.txt AC 214 ms 14788 KiB
01_random_20.txt AC 163 ms 14712 KiB
01_random_21.txt AC 132 ms 14708 KiB
01_random_22.txt AC 315 ms 14708 KiB
01_random_23.txt AC 337 ms 14712 KiB
01_random_24.txt AC 277 ms 14784 KiB
01_random_25.txt AC 385 ms 14780 KiB
01_random_26.txt AC 359 ms 14716 KiB
01_random_27.txt AC 388 ms 14784 KiB
01_random_28.txt AC 243 ms 14800 KiB
01_random_29.txt AC 386 ms 14788 KiB
01_random_30.txt AC 214 ms 3484 KiB