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;
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |