#include <bits/stdc++.h>
#define MN 10071
#define ML 20
using namespace std;
int n, s, A[MN], B[MN];
int F[(1<<21)];
vector<pair<int, int> > SOL;
void xo(int a, int b) {
--F[A[a]];
A[a] ^= A[b];
++F[A[a]];
SOL.push_back({a, b});
}
int main() {
cin >> n >> s;
for(int i = 1; i <= n; ++i)
cin >> A[i];
if(s == 1 || n <= ML){
for(int i = 1; i <= n; ++i) B[i] = A[i];
for(int i = 1; i < n; ++i) xo(i, i+1);
int pma = 0;
for(int i = 0; i < n-1; ++i){
pma = 0;
for(int j = 1; j <= n - i; ++j)
if(B[j] > B[pma]) pma = j;
for(int j = pma+1; j <= n - i; ++j){
xo(j, j-1);
swap(B[j], B[j-1]);
}
for(int j = max(pma-1, 1); j < n-i; ++j)
xo(j, j+1);
}
} else {
for(int j = (ML-1); j >= 0; --j){
for(int i = 1; i < n + j - (ML-1); ++i){
if((A[i] & (1<<j)) && A[i+1] & (1<<j)) xo(i, i + 1);
else if((A[i] & (1<<j))){
xo(i+1, i);
xo(i, i + 1);
}
}
}
}
// for(int i = 1; i <= n; ++i)
// cout << A[i] << " \n"[i==n];
cout << SOL.size() << "\n";
for(auto it : SOL) cout << it.first << " " << it.second << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
2380 KB |
Output is correct |
4 |
Correct |
5 ms |
4556 KB |
Output is correct |
5 |
Correct |
5 ms |
4684 KB |
Output is correct |
6 |
Correct |
5 ms |
4684 KB |
Output is correct |
7 |
Correct |
6 ms |
4684 KB |
Output is correct |
8 |
Correct |
5 ms |
4684 KB |
Output is correct |
9 |
Correct |
5 ms |
4684 KB |
Output is correct |
10 |
Correct |
5 ms |
4684 KB |
Output is correct |
11 |
Correct |
1 ms |
972 KB |
Output is correct |
12 |
Correct |
8 ms |
4812 KB |
Output is correct |
13 |
Correct |
8 ms |
4792 KB |
Output is correct |
14 |
Correct |
8 ms |
4772 KB |
Output is correct |
15 |
Correct |
8 ms |
4812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
2380 KB |
Output is correct |
4 |
Correct |
5 ms |
4556 KB |
Output is correct |
5 |
Correct |
5 ms |
4684 KB |
Output is correct |
6 |
Correct |
5 ms |
4684 KB |
Output is correct |
7 |
Correct |
6 ms |
4684 KB |
Output is correct |
8 |
Correct |
5 ms |
4684 KB |
Output is correct |
9 |
Correct |
5 ms |
4684 KB |
Output is correct |
10 |
Correct |
5 ms |
4684 KB |
Output is correct |
11 |
Correct |
1 ms |
972 KB |
Output is correct |
12 |
Correct |
8 ms |
4812 KB |
Output is correct |
13 |
Correct |
8 ms |
4792 KB |
Output is correct |
14 |
Correct |
8 ms |
4772 KB |
Output is correct |
15 |
Correct |
8 ms |
4812 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
5 ms |
4684 KB |
Output is correct |
18 |
Correct |
7 ms |
4808 KB |
Output is correct |
19 |
Correct |
7 ms |
4812 KB |
Output is correct |
20 |
Correct |
7 ms |
4808 KB |
Output is correct |
21 |
Correct |
7 ms |
4824 KB |
Output is correct |
22 |
Correct |
8 ms |
4808 KB |
Output is correct |
23 |
Correct |
7 ms |
4836 KB |
Output is correct |
24 |
Correct |
8 ms |
4800 KB |
Output is correct |
25 |
Correct |
7 ms |
4808 KB |
Output is correct |
26 |
Correct |
13 ms |
5064 KB |
Output is correct |
27 |
Correct |
12 ms |
5064 KB |
Output is correct |
28 |
Correct |
12 ms |
5076 KB |
Output is correct |
29 |
Correct |
12 ms |
5076 KB |
Output is correct |
30 |
Correct |
12 ms |
5064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
3 ms |
2508 KB |
Output is correct |
5 |
Correct |
9 ms |
4600 KB |
Output is correct |
6 |
Correct |
9 ms |
4720 KB |
Output is correct |
7 |
Correct |
11 ms |
4728 KB |
Output is correct |
8 |
Correct |
9 ms |
4624 KB |
Output is correct |
9 |
Correct |
9 ms |
4644 KB |
Output is correct |
10 |
Correct |
9 ms |
4680 KB |
Output is correct |
11 |
Correct |
9 ms |
4040 KB |
Output is correct |
12 |
Correct |
11 ms |
4468 KB |
Output is correct |
13 |
Correct |
10 ms |
4296 KB |
Output is correct |
14 |
Correct |
12 ms |
4408 KB |
Output is correct |
15 |
Correct |
12 ms |
1248 KB |
Output is correct |