Submission #1224210

#TimeUsernameProblemLanguageResultExecution timeMemory
1224210AishaXor Sort (eJOI20_xorsort)C++20
0 / 100
672 ms589824 KiB
#include "bits/stdc++.h"

using namespace std;

#define int long long

signed main () {
    int n, s;
    cin >> n >> s;

    vector <int> a(n);
    for (int i = 0; i < n; i ++) cin >> a[i];

    vector <pair <int, int>> v;
    while (!is_sorted(a.begin(), a.end())) {
        for (int i = 1; i < n; i ++) {
            if (a[i - 1] < a[i]) continue;
            if ((a[i - 1] ^ a[i]) < a[i]) a[i - 1] ^= a[i], v.push_back({i - 1, i});
            else a[i] ^= a[i - 1], v.push_back({i, i - 1});
        }
        //for (int i = 0; i < n; i ++) cout << a[i] << ' '; 
        //cout << endl;
    }

    cout << v.size() << endl;
    for (int i = 0; i < (int)v.size(); i ++) cout << v[i].first + 1 << ' ' << v[i].second + 1 << endl;

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