# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1044925 | mar | Xor Sort (eJOI20_xorsort) | C++14 | 41 ms | 1172 KiB |
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;
typedef long long ll;
ll arr[1000007];
int main(){
int n,s; cin>>n>>s;
for (int i = 0; i < n; i++){
cin>>arr[i];
}
vector<pair<int,int>> ans;
if(s==2){
for(int bit = 22; bit >= 0; bit--){
for(int i = 0; i+1 < n; i++){
if(arr[i]&(1LL<<bit)){
if (arr[i+1]&(1LL<<bit)){
ans.push_back({i+1,i+2});
arr[i]^=arr[i+1];
} else {
ans.push_back({i+2,i+1});
ans.push_back({i+1,i+2});
arr[i+1]^=arr[i];
arr[i]^=arr[i+1];
}
}
}
if((n>=1) && (arr[n-1]&(1LL<<bit))){
n--;
}
}
} else {
for(int i = n; i >= 1; i--){
int mx = 0;
for(int j = 0; j < i; j++){
if(arr[j]>arr[mx]) mx=j;
if(j+1<i){
ans.push_back({j+1,j+2});
}
}
for(int j = mx-2; j >= 0; j--){
ans.push_back({j+1,j+2});
}
for(int j = mx; j+1 < i; j++){
ans.push_back({j+2,j+1});
}
for(int k = mx; k + 1 < i; k++){
swap(arr[k],arr[k+1]);
}
}
for(int i = n; i >= 2; i--){
ans.push_back({i-1,i});
}
}
cout<<ans.size()<<endl;
for (int i = 0; i < ans.size(); i++){
cout<<ans[i].first<<" "<<ans[i].second<<endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |