제출 #1189436

#제출 시각아이디문제언어결과실행 시간메모리
1189436zadniprovskaXor Sort (eJOI20_xorsort)C++20
25 / 100
73 ms18568 KiB
#include <bits/stdc++.h>

using namespace std;

#define el '\n'
#define ll long long
#define ld long double
#define ull unsigned long long
#define pll pair<long long, long long>
#define ppll pair< long long, pair<long long, long long> >
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()

const ll DIM = 1e6+7;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const ll maxlog = 20;

ll a[DIM];


void solve() {

    ll n, s;
    cin >> n >> s;

    for (int i=1; i<=n; i++) {
        cin >> a[i];
    }

    ll flag = 1, op = 0;
    vector<pll> ans;
    while (flag) {

        flag = 0;
        for (int i=1; i<n; i++) {
            if (a[i] > a[i+1]) {

                flag = 1;

                ans.pb({i+1, i});
                ans.pb({i, i+1});
                ans.pb({i+1, i});

                op += 3;

                swap(a[i], a[i+1]);

            }
        }

    }

    cout << op << el;
    for (auto [x, y] : ans) {
        cout << x << " " << y << el;
    }




}



signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    //freopen("nocross.in", "r", stdin);
    //freopen("nocross.out", "w", stdout);

    int ntest = 1;
    //cin >> ntest;
    while (ntest--){
        solve();
    }
    return 0;

}
;
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...