0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-14 02:58:47 +00:00
OI-codes/NFLSOJ/0/3631/3631.cpp

47 lines
841 B
C++
Raw Normal View History

// #include <iostream>
#include <algorithm>
#include <fstream>
#include <utility>
#include <vector>
// using std::cin;
// using std::cout;
std::ifstream cin("swap.in");
std::ofstream cout("swap.out");
const char endl = '\n';
const int N = 1e5 + 5;
int n, a[N], p[N];
std::vector<std::pair<int, int>> ans;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
p[a[i]] = i;
}
for (int i = 1; i <= n; i++) {
if (a[i] != i) {
int x = i, y = p[i];
ans.emplace_back(p[x], p[y]);
std::swap(a[x], a[y]);
p[a[x]] = x, p[a[y]] = y;
}
}
cout << ans.size() << endl;
for (auto e : ans) {
cout << e.first << ' ' << e.second << endl;
}
return 0;
}