Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using namespace std;

int binary(vector<int>& a, int n) {
	int start = 0, end = a.size() - 1;
	while (start<=end) {
		int mid = (start + end) / 2;
		if (a[mid] == n) return mid;
		if (a[mid] > n) end = mid - 1;
		else start = mid + 1;
	}
	return -5;;
}

void solve() {
	long long n, count = 0;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n), f, s;
	iota(b.begin(), b.end(), 1);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		//cout << b[i] << " ";
	}
	int end = n;
	for (int i = n - 1; i > 0; i--) {
		int c = binary(b, a[i]);
		//cout << c; return;
		if (c == b.size() - 1) {
			f.push_back(b[c]);
			f.push_back(b[c - 1]);
			s.push_back(b[c - 1]);
			s.push_back(b[c]);
			//cout << b[c] << " " << b[c - 1] << endl;
			//cout << b[c - 1] << " " << b[c] << endl;
			count += 2;
		}
		else {
			for (int j = c + 1; j < b.size(); j++) {
				f.push_back(b[j]);
				s.push_back(b[j - 1]);
				//cout << b[j] << " " << b[j - 1] << endl;
				swap(b[j], b[j - 1]);
				count++;
			}
		}
		b.erase(b.end()-1);
	}
	cout << count << endl;
	for (int i = 0; i < count; i++) {
		cout << f[i] << " " << s[i] << endl;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
		cout << endl;
	}

	return 0;
}

Submission (verdict: Accepted):
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using namespace std;

int binary(vector<int>& a, int n, int start, int end) {
	while (start<=end) {
		int mid = (start + end) / 2;
		if (a[mid] == n) return mid;
		if (a[mid] > n) end = mid - 1;
		else start = mid + 1;
	}
	return -1;
}

void solve() {
	long long n, count = 0;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n), f, s;
	iota(b.begin(), b.end(), 1);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int end = n - 1, start = 0;
	for (int i = n - 1; i >= 0; i--) {
		int c = binary(b, a[i], start, end); 
		for (int j = c - 1; j >= 0; j--) {
			f.push_back(b[j + 1]);
			s.push_back(b[j]);
			swap(b[j + 1], b[j]);
			count++;
		}
		start++;
	}
	cout << count << endl;
	for (int i = 0; i < count; i++) {
		cout << f[i] << " " << s[i] << endl;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
		cout << endl;
	}

	return 0;
}