Advertisement
Fastrail08

Count zero XOR pairs

Aug 16th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6. void move(vector<int> &v, int &j){
  7.   while(j < (int) v.size() && v[j - 1] == v[j]){
  8.     j++;
  9.   }
  10. }
  11.  
  12. int countZeroXORs(vector<int> &v){
  13.   int count = 0;
  14.   sort(v.begin(), v.end());
  15.   for(int i = 0,j = 1; i < (int) v.size();){
  16.     move(v, j);
  17.     count += ((j - i) * (j - i -1)) / 2;
  18.     i = j;
  19.     j += 1;
  20.   }
  21.   return count;
  22. }
  23.  
  24. int main()
  25. {
  26.     int n;
  27.     cin >> n;
  28.     vector<int> v(n);
  29.     for(int i = 0; i < n; i++){
  30.       cin >> v[i];
  31.     }
  32.     cout << countZeroXORs(v) << '\n';
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement