#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
736 KB |
Output is correct |
5 |
Correct |
2 ms |
800 KB |
Output is correct |
6 |
Correct |
2 ms |
856 KB |
Output is correct |
7 |
Correct |
2 ms |
732 KB |
Output is correct |
8 |
Correct |
2 ms |
736 KB |
Output is correct |
9 |
Correct |
2 ms |
736 KB |
Output is correct |
10 |
Correct |
2 ms |
736 KB |
Output is correct |
11 |
Correct |
2 ms |
856 KB |
Output is correct |
12 |
Correct |
3 ms |
732 KB |
Output is correct |
13 |
Correct |
2 ms |
732 KB |
Output is correct |
14 |
Correct |
2 ms |
736 KB |
Output is correct |
15 |
Correct |
2 ms |
736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
736 KB |
Output is correct |
5 |
Correct |
2 ms |
800 KB |
Output is correct |
6 |
Correct |
2 ms |
856 KB |
Output is correct |
7 |
Correct |
2 ms |
732 KB |
Output is correct |
8 |
Correct |
2 ms |
736 KB |
Output is correct |
9 |
Correct |
2 ms |
736 KB |
Output is correct |
10 |
Correct |
2 ms |
736 KB |
Output is correct |
11 |
Correct |
2 ms |
856 KB |
Output is correct |
12 |
Correct |
3 ms |
732 KB |
Output is correct |
13 |
Correct |
2 ms |
732 KB |
Output is correct |
14 |
Correct |
2 ms |
736 KB |
Output is correct |
15 |
Correct |
2 ms |
736 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
840 KB |
Output is correct |
18 |
Correct |
6 ms |
992 KB |
Output is correct |
19 |
Correct |
4 ms |
988 KB |
Output is correct |
20 |
Correct |
4 ms |
992 KB |
Output is correct |
21 |
Correct |
3 ms |
992 KB |
Output is correct |
22 |
Correct |
4 ms |
988 KB |
Output is correct |
23 |
Correct |
4 ms |
1100 KB |
Output is correct |
24 |
Correct |
3 ms |
992 KB |
Output is correct |
25 |
Correct |
3 ms |
1080 KB |
Output is correct |
26 |
Correct |
4 ms |
988 KB |
Output is correct |
27 |
Correct |
4 ms |
992 KB |
Output is correct |
28 |
Correct |
3 ms |
1088 KB |
Output is correct |
29 |
Correct |
4 ms |
992 KB |
Output is correct |
30 |
Correct |
4 ms |
1104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
992 KB |
Output is correct |
6 |
Correct |
3 ms |
988 KB |
Output is correct |
7 |
Correct |
3 ms |
992 KB |
Output is correct |
8 |
Correct |
3 ms |
992 KB |
Output is correct |
9 |
Correct |
3 ms |
844 KB |
Output is correct |
10 |
Correct |
3 ms |
992 KB |
Output is correct |
11 |
Correct |
3 ms |
992 KB |
Output is correct |
12 |
Correct |
3 ms |
992 KB |
Output is correct |
13 |
Correct |
3 ms |
992 KB |
Output is correct |
14 |
Correct |
3 ms |
992 KB |
Output is correct |
15 |
Correct |
4 ms |
988 KB |
Output is correct |