# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
641888 | manizare | Xor Sort (eJOI20_xorsort) | C++14 | 7 ms | 1484 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>
#define all(a) a.begin(),a.end()
#define pb push_back
#define int long long
using namespace std ;
const int maxn = 1e7 , maxq = 1e5+10 , mod = 998244353 ,inf = 1e18 ;
int a[maxn] ;
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n , s ;
cin >>n >> s;
for(int i =1 ; i <= n ; i++){
cin >> a[i];
}
vector <pair <int ,int > > ans ;
int r = n ;
for(int i = 19 ; i >= 0 ; i--){
for(int j =2 ;j <= r ; j++){
int x = ((a[j] & (1<<i)) != 0) , y =((a[j-1] & (1<<i)) != 0) ;
if(x==y && x==1){
a[j-1]^=a[j];
ans.pb({j-1,j});
}else if(x!=y && x==0){
ans.pb({j,j-1});
a[j]^=a[j-1];
ans.pb({j-1,j});
a[j-1]^=a[j];
}
}
if(((1<<i)&a[r]) !=0)r--;
}
cout << ans.size() << "\n";
for(int i = 0 ; i< ans.size() ; i++){
cout <<ans[i].first << " " << ans[i].second << "\n" ;
}
cout << "\n";
return 0 ;
}
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... |