0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-09 16:58:48 +00:00
Baoshuo Ren 2022-11-18 13:56:14 +08:00
parent 9feffbec47
commit 8530e20eb0
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

46
NFLSOJ/0/3631/3631.cpp Normal file
View File

@ -0,0 +1,46 @@
// #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;
}