#include <bits/stdc++.h>
#include <fstream>
using namespace std;
// #define int long long
#define endl '\n'
const int mxn = 501;
const int mod = 1e8;
// int dx[] = {0 , 0 , 1 , -1};
// int dy[] = {1 , -1 , 0 , 0};
//DFS
//----------------------------------
// vector<int> adj[mxn];
// int n , m;
// bool vis[mxn];
// int P[mxn];
// int rem[mxn];
// void dfs(int i){
// vis[i] = 1;
// for(auto j : adj[i]){
// if(!vis[j]){
// P[j] = i;
// dfs(j);
// }
// }
// return;
// }
//----------------------------------
//Seg-Tree
//----------------------------------
// int Tree[1 << (int)(ceil(log2(mxn))) + 1];
// int N = 1 << (int)(ceil(log2(mxn)));
// int l ,r;
// int Search(int i , int lr , int rr){
// if(lr >= l and rr <= r){
// return Tree[i];
// }
// if(lr > r or rr < l) return -1;
// return max(Search(i * 2 , lr , (lr + rr) / 2) , Search(i * 2 + 1 , (lr + rr) / 2 + 1 , rr));
// }
// void update(int i){
// while(i /= 2){
// Tree[i] = max(Tree[i * 2] , Tree[i * 2 + 1]);
// }
// return;
// }
//----------------------------------
//comp
//----------------------------------
// map<int , int>mp;
// map<int , int>pm;
// void comp(set<int>s)
// {
// int idx = 0;
// for(auto i : s){
// mp[i] = idx;
// pm[idx] = i;
// idx ++;
// }
// }
//----------------------------------
int n , s;
int A[200];
vector<array<int , 2>>ans;
void swp (int a , int b){//from a to b
if(a > b){
for(int i = a ; i > b ; i--){
ans.push_back({i , i - 1});
ans.push_back({i - 1 , i});
ans.push_back({i , i - 1});
swap(A[i] , A[i - 1]);
}
}
else {
for(int i = a ; i < b ; i++){
ans.push_back({i , i + 1});
ans.push_back({i + 1 , i});
ans.push_back({i , i + 1});
swap(A[i] , A[i + 1]);
}
}
return;
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> s;
int b[n];
for(int i = 0 ; i < n; i++){
cin >> A[i];
b[i] = A[i];
}
sort(b , b + n);
map<int , int>mp;
for(int i = 0 ; i < n; i++){
mp[b[i]] = i;
}
for(int i = n - 1; i >= 0 ; i--){
if(i != mp[A[i]]) swp(i , mp[A[i]]);
}
cout << ans.size() << endl;
for(auto [a , b] : ans){
cout << a << " " << b << endl;
}
}
Compilation message
xorsort.cpp: In function 'int main()':
xorsort.cpp:101:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
101 | for(auto [a , b] : ans){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Integer 0 violates the range [1, 5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Integer 0 violates the range [1, 5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Integer 0 violates the range [1, 5] |
2 |
Halted |
0 ms |
0 KB |
- |