#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s;
cin >> n >> s;
vector<int> a(n), b(n);
vector<pair<int,int>> op;
map<int,int> pos;
for(int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
pos[a[i]] = i;
}
sort(b.begin(), b.end());
for(int i = 0; i < n; i++) {
for(int j = pos[b[i]]; j > i; j--) {
op.push_back({j-1, j});
op.push_back({j, j-1});
op.push_back({j-1, j});
pos[a[j-1]] = j;
a[j] = a[j-1];
}
pos[b[i]] = i;
a[i] = b[i];
}
cout << op.size() << "\n";
for(auto i : op) cout << i.first+1 << " " << i.second+1 << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
616 KB |
Output is correct |
8 |
Correct |
3 ms |
684 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
5 ms |
848 KB |
Output is correct |
13 |
Correct |
5 ms |
944 KB |
Output is correct |
14 |
Correct |
5 ms |
868 KB |
Output is correct |
15 |
Correct |
5 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
616 KB |
Output is correct |
8 |
Correct |
3 ms |
684 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
5 ms |
848 KB |
Output is correct |
13 |
Correct |
5 ms |
944 KB |
Output is correct |
14 |
Correct |
5 ms |
868 KB |
Output is correct |
15 |
Correct |
5 ms |
848 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
596 KB |
Output is correct |
18 |
Correct |
5 ms |
848 KB |
Output is correct |
19 |
Correct |
4 ms |
848 KB |
Output is correct |
20 |
Correct |
4 ms |
848 KB |
Output is correct |
21 |
Correct |
7 ms |
892 KB |
Output is correct |
22 |
Correct |
4 ms |
848 KB |
Output is correct |
23 |
Correct |
6 ms |
848 KB |
Output is correct |
24 |
Correct |
5 ms |
848 KB |
Output is correct |
25 |
Correct |
4 ms |
848 KB |
Output is correct |
26 |
Incorrect |
8 ms |
1356 KB |
Integer 59568 violates the range [0, 40000] |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
848 KB |
Output is correct |
5 |
Incorrect |
96 ms |
12544 KB |
Integer 764742 violates the range [0, 40000] |
6 |
Halted |
0 ms |
0 KB |
- |