#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define speed cin.tie (0) -> sync_with_stdio (0);ios_base::sync_with_stdio(false);cin.tie(0);
const int maxn = 1005;
int n, s;
int a[maxn];
vector<pair<int, int>> ans;
void ptt(int x, int y)
{
ans.push_back({x + 1, y + 1});
a[x] ^= a[y];
}
void solve1()
{
int b[n + 5];
for(int i=0; i<n; i++) b[i] = a[i];
for(int i=0; i<n-1; i++) ptt(i, i + 1);
for(int i=n-1; i>=0; i--)
{
int cur = 0;
for(int j=1; j<=i; j++) if (b[j] > b[cur]) cur = j;
for(int j=cur+1; j<=i; j++) ptt(j, j - 1);
for(int j=max(0ll, cur-1); j<i; j++) ptt(j, j + 1);
for(int j=cur; j<i; j++) swap(b[j], b[j + 1]);
}
// for(int i=0; i<n; i++) cout<<b[i]<<" ";
// cout<<endl;
}
void solve2()
{
int l = n;
for(int bt=19; bt>=0; bt--)
{
bool f = 0;
for(int i=0; i<n; i++)
{
if (a[i] & (1 << bt))
{
f = 1;
break;
}
}
if (!f) continue;
l--;
for(int i=0; i<l; i++)
{
if (a[i] & (1 << bt) && !(a[i + 1] & (1 << bt)))
{
ptt(i + 1, i);
ptt(i, i + 1);
}
else if (a[i] & (1 << bt) && a[i + 1] & (1 << bt)) ptt(i, i + 1);
}
}
}
void solve()
{
cin>>n>>s;
for(int i=0; i<n; i++) cin>>a[i];
if (s == 1) solve1();
else solve2();
cout<<ans.size()<<endl;
for(auto [i, j] : ans) cout<<i<<" "<<j<<endl;
}
signed main ()
{
speed
// freopen("feast.in", "r", stdin);
// freopen("feast.out", "w", stdout);
int _ = 1;
// cin>>_;
while(_--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
736 KB |
Output is correct |
5 |
Correct |
2 ms |
736 KB |
Output is correct |
6 |
Correct |
2 ms |
736 KB |
Output is correct |
7 |
Correct |
1 ms |
736 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
736 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
3 ms |
992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
736 KB |
Output is correct |
5 |
Correct |
2 ms |
736 KB |
Output is correct |
6 |
Correct |
2 ms |
736 KB |
Output is correct |
7 |
Correct |
1 ms |
736 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
736 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
3 ms |
992 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
736 KB |
Output is correct |
18 |
Correct |
3 ms |
992 KB |
Output is correct |
19 |
Correct |
2 ms |
992 KB |
Output is correct |
20 |
Correct |
3 ms |
992 KB |
Output is correct |
21 |
Correct |
3 ms |
992 KB |
Output is correct |
22 |
Correct |
3 ms |
992 KB |
Output is correct |
23 |
Correct |
3 ms |
992 KB |
Output is correct |
24 |
Correct |
2 ms |
992 KB |
Output is correct |
25 |
Correct |
3 ms |
988 KB |
Output is correct |
26 |
Correct |
5 ms |
1500 KB |
Output is correct |
27 |
Correct |
5 ms |
1500 KB |
Output is correct |
28 |
Correct |
5 ms |
1500 KB |
Output is correct |
29 |
Correct |
5 ms |
1500 KB |
Output is correct |
30 |
Correct |
5 ms |
1500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
4 ms |
1244 KB |
Output is correct |
6 |
Correct |
4 ms |
1244 KB |
Output is correct |
7 |
Correct |
4 ms |
1244 KB |
Output is correct |
8 |
Correct |
4 ms |
1240 KB |
Output is correct |
9 |
Correct |
3 ms |
1244 KB |
Output is correct |
10 |
Correct |
3 ms |
1244 KB |
Output is correct |
11 |
Correct |
4 ms |
1244 KB |
Output is correct |
12 |
Correct |
4 ms |
1244 KB |
Output is correct |
13 |
Correct |
4 ms |
1244 KB |
Output is correct |
14 |
Correct |
4 ms |
1244 KB |
Output is correct |
15 |
Correct |
5 ms |
1500 KB |
Output is correct |