-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathc.cc
60 lines (60 loc) · 1.28 KB
/
c.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// https://codeforces.com/contest/1148/problem/C
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ii = tuple<int, int>;
using vii = vector<ii>;
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
vi a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vii p;
int i = 0;
while (i < n) {
if (a[i] == i + 1) {
i++; continue;
}
if (a[i] - (i + 1) >= n / 2) {
p.push_back({i + 1, a[i]});
int x = a[i] - 1;
swap(a[i], a[x]);
continue;
}
if (n - a[i] >= n / 2) {
p.push_back({i + 1, n});
p.push_back({n, a[i]});
int x = a[i] - 1;
swap(a[i], a[n - 1]);
swap(a[n - 1], a[x]);
continue;
}
if (i >= n / 2) {
p.push_back({1, i + 1});
p.push_back({1, a[i]});
p.push_back({1, i + 1});
int x = a[i] - 1;
swap(a[0], a[i]);
swap(a[0], a[x]);
swap(a[0], a[i]);
continue;
}
p.push_back({n, i + 1});
p.push_back({1, n});
p.push_back({1, a[i]});
p.push_back({1, n});
int x = a[i] - 1;
swap(a[n - 1], a[i]);
swap(a[0], a[n - 1]);
swap(a[0], a[x]);
swap(a[0], a[n - 1]);
}
cout << p.size() << "\n";
for (ii x : p) {
int u, v;
tie(u, v) = x;
cout << u << " " << v << "\n";
}
}