This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Muallif: Mansuraliyev Husanboy Murotali o'g'li >> NamPS
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(a) a.begin(), a.end()
#define F first
#define S second
/*struct segtree{
vector<int> t;
int sz=0;
void init(int n){
t.assign(4*n+1,0);
sz=n;
}
void upd(int x, int l, int r, int ind, int val){
if(l==r){
t[x]=val;return;
}
int m=(l+r)/2;
if(ind>m){
upd(x*2+1,m+1,r,ind,val);
}else upd(x*2,l,m,ind,val);
t[x]=t[x*2]^t[x*2+1];
}
void upd(int ind, int val){
upd(1,1,sz,ind,val);
}
int get(int x, int l, int r, int lx, int rx){
if(lx<=l&&r<=rx){
return t[x];
}
if(r<lx||rx<l){
return 0;
}
int m=(l+r)/2;
return get(x*2,l,m,lx,rx)^get(x*2+1,m+1,r,lx,rx);
}
int get(int l,int r){
return get(1,1,sz,l,r);
}
};
segtree t;*/
void solve(){
int n,s;
cin>>n>>s;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
vector<pair<int,int> > ans;
if(s==1){
for(int i=1;i<n;i++){
for(int j=0;j<n-i;j++){
if(a[j]>a[j+1]){
ans.push_back({j,j+1});
ans.push_back({j+1,j});
ans.push_back({j,j+1});
swap(a[j+1],a[j]);
}
}
}
cout<<ans.size()<<"\n";
for(auto u:ans){
cout<<u.F+1<<' '<<u.S+1<<"\n";
}
return;
}
for(int i=19;i>=0;i--){
for(int j=0;j<n-1;j++){
if(a[j]&(1<<i)){
if(a[j+1]&(1<<i)){
ans.push_back({j,j+1});
a[j]^=a[j+1];
}else{
ans.push_back({j+1,j});
ans.push_back({j,j+1});
a[j+1]^=a[j];
a[j]^=a[j+1];
}
}
}
}
cout<<ans.size()<<"\n";
for(auto u:ans){
cout<<u.F+1<<' '<<u.S+1<<"\n";
}
}
int main(){
ios;
//int t=1; cin>>t; while(t--)
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |