#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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Not sorted |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Not sorted |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
500 KB |
Not sorted |
2 |
Halted |
0 ms |
0 KB |
- |