제출 #775050

#제출 시각아이디문제언어결과실행 시간메모리
775050vjudge1Xor Sort (eJOI20_xorsort)C++17
25 / 100
122 ms18544 KiB
// #pragma GCC optimize("Ofast,unroll-loops")

#ifdef MINHDEPTRAI
 
#include "/Library/Developer/CommandLineTools/usr/include/c++/v1/bits/stdc++.h"
#include <chrono>
#define __gcd(a, b) gcd(a, b)
using namespace std ::chrono;
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#define foru(i, a, b) for (int i = a; i <= b; ++i)
#define ford(i, a, b) for (int i = a; i >= b; --i)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp(a, b) make_pair(a, b)
// #define int long long
typedef pair<int, int>  pii;
typedef pair<pair<int, int>, int> piii;
#define endl '\n'
const string name_minh = "9";
#define int long long
const int maxN = 2e5 + 5;
const int mod = 1;

const int inf = 1e9;
int n, arr[maxN], k;

vector<pair<int, int>> ans;
void push_arr(int i, int j){
    ans.push_back(mp(j, i));
    ans.push_back(mp(i, j));
    ans.push_back(mp(j, i));
}

void solve(){
    cin >> n >> k;
    foru(i, 1, n){
        cin >> arr[i];
    }
    bool swapped = true;
    int start = 1, end = n;

    while(swapped){
        swapped = false;

        foru(i, start, end - 1){
            if(arr[i] > arr[i + 1]){
                swap(arr[i], arr[i + 1]);
                push_arr(i + 1, i);
                swapped = true;
            }
        }
        if(!swapped) break;
        end--;
        swapped = false;
        ford(i, end, start + 1){
            if(arr[i] < arr[i - 1]){
                swap(arr[i], arr[i - 1]);
                push_arr(i, i - 1);
                swapped = true;
            }
        }

        start++;
    }

  
    cout << ans.size() << endl;
    for(auto x: ans){
        cout << x.first << " " << x.second << endl;
    }
   
    
}
signed main(){
    IOS
    // #ifdef MINHDEPTRAI 
    // ifstream cin(name_minh + ".in");
    // ofstream cout(name_minh + ".out");
    // #endif
    solve();
  
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...