#pragma optimize ("g",on)
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#include <bits/stdc++.h>
#define pb push_back
#define SS ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
// #define int long long
#define all(v) v.begin(),v.end()
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 1, inf = 1e9, mod = 998244353;
void solve(){
int n, s;
cin >> n >> s;
int a[n + 1];
for(int i = 1; i <= n; i++){
cin >> a[i];
}
/*
a[i] ^ a[i + 1] a[i + 1]
a[i] ^ a[i + 1] a[i]
a[i + 1] a[i]
*/
vector<pair<int, int>> v;
while(true){
if(is_sorted(a + 1, a + n + 1)) break;
for(int j = 1; j < n; j++){
if(a[j] > a[j + 1]){
if((a[j] ^ a[j + 1]) > a[j]){
v.push_back({j + 1, j});
a[j + 1] ^= a[j];
}
else if((a[j] ^ a[j + 1]) < a[j]){
v.push_back({j, j + 1});
a[j] ^= a[j + 1];
}
else{
v.push_back({j, j + 1});
v.push_back({j + 1, j});
v.push_back({j, j + 1});
swap(a[j], a[j + 1]);
}
}
}
}
cout << v.size() << '\n';
for(auto [i, j] : v){
cout << i << ' ' << j << '\n';
}
}
signed main(){
SS
// freopen("trains.in", "r", stdin);
// freopen("trains.out", "w", stdout);
int t = 1;
// cin >> t;
while(t--){
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |