#include <bits/stdc++.h>
#define MN 10071
#define ML 20
using namespace std;
int n, s, A[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)
for(int j = n; j >= 2; --j)
if(A[j] < A[j-1]){
if(F[A[j] ^ A[j-1]] || (A[j] ^ A[j-1]) > A[j]){
xo(j, j-1);
xo(j-1, j);
xo(j, j-1);
}
else {
xo(j-1, j);
}
}
} 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Incorrect |
4 ms |
3420 KB |
Not sorted |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Incorrect |
4 ms |
3420 KB |
Not sorted |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
3 ms |
2508 KB |
Output is correct |
5 |
Correct |
10 ms |
4680 KB |
Output is correct |
6 |
Correct |
9 ms |
4680 KB |
Output is correct |
7 |
Correct |
11 ms |
4680 KB |
Output is correct |
8 |
Correct |
9 ms |
4648 KB |
Output is correct |
9 |
Correct |
9 ms |
4680 KB |
Output is correct |
10 |
Correct |
12 ms |
4680 KB |
Output is correct |
11 |
Correct |
9 ms |
3972 KB |
Output is correct |
12 |
Correct |
10 ms |
4424 KB |
Output is correct |
13 |
Correct |
11 ms |
4424 KB |
Output is correct |
14 |
Correct |
10 ms |
4468 KB |
Output is correct |
15 |
Correct |
10 ms |
1220 KB |
Output is correct |