Submission #641882

#TimeUsernameProblemLanguageResultExecution timeMemory
641882manizareXor Sort (eJOI20_xorsort)C++14
0 / 100
1 ms212 KiB
#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 ; cin >>n ; for(int i =1 ; i <= n ; i++){ cin >> a[i]; } vector <pair <int ,int > > ans ; int r = n ; for(int i = 20 ; 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)

xorsort.cpp: In function 'int main()':
xorsort.cpp:36:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for(int i = 0 ; i< ans.size() ; i++){
      |                  ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...