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;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,t;
cin>>n>>t;
int a[n+5],b[n+5];
set<pair<int,int>>st;
for(int x=1;x<=n;x++)
{
cin>>a[x];
st.insert({a[x],x});
b[x]=a[x];
}
vector<pair<int,int>>ans;
if(t==1)
{
for(int x=1;x<n;x++)
{
ans.push_back({x,x+1});
b[x]=(b[x]^b[x+1]);
}
int I=n;
while(st.size())
{
auto [v,i]=*st.rbegin();
st.erase({v,i});
if(i==I)continue;
//cout<<v<<' '<<i<<'\n';
for(int x=i-1;x>1;x--)
{
ans.push_back({x-1,x});
b[x-1]=(b[x-1]^b[x]);
}
for(int x=i+1;x<=I;x++)
{
ans.push_back({x,x-1});
b[x]=(b[x]^b[x-1]);
}
for(int x=2;x<=I;x++)
{
ans.push_back({x-1,x});
b[x-1]=(b[x-1]^b[x]);
if(x>i)
{
st.erase({a[x],x});
swap(a[x],a[x-1]);
st.insert({a[x-1],x-1});
}
}
I--;
}
}
cout<<ans.size()<<'\n';
for(auto [x,y]:ans)cout<<x<<' '<<y<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |