#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;
const ll MAXN = 1E3+16;
ll th[MAXN];
vii ans;
void fop (vll &ve, ll i, ll j) {
ans.push_back({ i, j });
ve[i] ^= ve[j];
th[i] ^= th[j];
}
void fswap (vll &ve, ll i) { // swap the indices (i, i+1)
fop(ve, i, i+1);
fop(ve, i+1, i);
fop(ve, i, i+1);
}
void fsolve (vll &ve, ll l, ll r, ll bit) {
if (bit == -1 || l > r) return;
for (ll i = l; i <= r; i++) th[i] = ve[i]>>bit&1;
for (ll i = l; i <= r; i++) {
for (ll j = l; j < r; j++) {
if (ve[j] > ve[j+1]) {
fswap(ve, j);
}
}
}
// ll il = l, ir = r;
// while (il < ir) {
// while (il < ir && th[il] == 0) il++;
// while (il < ir && th[ir] == 1) ir--;
// if (il >= ir) break;
// fswap(ve, il, ir);
// il++; ir--;
// }
for (ll i = l; i <= r; i++) th[i] = ve[i]>>bit&1;
assert(is_sorted(th+l, th+r+1));
ll mid = r;
while (th[mid] == 1) mid--;
fsolve(ve, l, mid, bit-1);
fsolve(ve, mid+1, r, bit-1);
}
int main () {
cin.tie(nullptr) -> sync_with_stdio(false);
ll n, s;
cin >> n >> s;
vll ve(n);
for (ll &i : ve) cin >> i;
fsolve(ve, 0, n-1, 19);
cout << ans.size() << '\n';
for (auto [i, j] : ans) cout << i+1 << ' ' << j+1 << '\n';
// for (ll i : ve) cerr << i << ' ';
return 0;
}
/*
3, 2
3, 1
2, 1
2, 3
1, 3
2, 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |