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 a[1001], n, s;
vector<pair<int, int>>op;
void s1(){
int b[n];
for(int i = 0;i < n; i++)b[i] = a[i];
for(int i = 0;i < n-1; i++)op.push_back({i, i+1});
for(int i = n-1; i>=0; i--){
int mxi = 0;
for(int j = 0;j <= i; j++)if(b[j] > b[mxi])mxi = j;
for(int j = mxi; j < i; j++)op.push_back({j+1, j});
for(int j = mxi; j >=1; j--)op.push_back({j, j-1});
}
}
void s2(){
int r=n-1;
for(int i = 19; i>=0; i--){
bool flag = 0;
int x=0;
for(int j = 0;j < r; j++){
int bt = (1 << i);
if(a[j+1] > (1<<i))break;
if((bt&a[j]) and !(bt&a[j+1]))op.push_back({j+1, j}), a[j+1]^=a[j], x+=10;
if((bt&a[j]) and (bt&a[j+1]))op.push_back({j, j+1}), a[j]^=a[j+1], x+=1000;
}
// for(int i = 0;i < n; i++)cout << a[i] << " ";
//cout <<endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
for(int i = 0;i < n; i++)cin >> a[i];
if(s==1)s1();
else s2();
cout << op.size() << endl;
for(auto [i, j] : op)cout << i+1 << " " << j+1 << endl;
// for(int i = 0;i < n; i++)cout << a[i] << " ";
}
Compilation message (stderr)
xorsort.cpp: In function 'void s2()':
xorsort.cpp:22:14: warning: unused variable 'flag' [-Wunused-variable]
22 | bool flag = 0;
| ^~~~
xorsort.cpp: In function 'int main()':
xorsort.cpp:51:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
51 | for(auto [i, j] : op)cout << i+1 << " " << j+1 << endl;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |