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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, S;
cin >> n >> S;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<array<int, 2>> res;
auto add = [&](int u, int v) {
res.push_back({u + 1, v + 1});
};
if (S == 1) {
for (int i = n - 1; i >= 0; --i) {
int p = -1;
for (int j = 0; j <= i; ++j) {
if (p == -1 || a[p] < a[j]) {
p = j;
}
if (j) {
add(j - 1, j);
}
}
for (int j = p + 1; j <= i; ++j) {
add(j, j - 1);
}
for (int j = p - 2; j >= 0; --j) {
add(j, j + 1);
}
for (int j = p; j + 1 < n; ++j) {
swap(a[j], a[j + 1]);
}
}
for (int i = n - 2; i >= 0; --i) {
add(i, i + 1);
}
} else {
int m = n;
for (int j = 19; j >= 0; --j) {
for (int i = 0; i < m; ++i) {
if (a[i] >> j & 1) {
while (i + 1 < m) {
if (!(a[i + 1] >> j & 1)) {
a[i + 1] ^= a[i];
add(i + 1, i);
}
a[i] ^= a[i + 1];
add(i, i + 1);
++i;
}
--m;
}
}
}
}
cout << res.size() << "\n";
for (auto [x, y] : res) {
cout << x << " " << y << "\n";
}
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... |