This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
}
void fswap (vll &ve, ll i, ll j) {
fop(ve, i, j);
fop(ve, j, i);
fop(ve, i, j);
}
void fsolve (vll &ve, ll l, ll r, ll bit) {
if (bit == -1) return;
for (ll i = l; i <= r; i++) th[i] = ve[i]>>bit&1;
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |