Advertisement
dmkozyrev

563.cpp

Apr 1st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <vector>
  3. #include <cmath>
  4. #include <cassert>
  5. #include <algorithm>
  6.  
  7. int solve_slow(const std::vector<int>& a) {
  8.     const int n = (int)a.size();
  9.     int s = 0; for (auto it : a) s ^= it;
  10.     for (int i = 0; i < n-1; ++i) {
  11.         int b = 0;
  12.         for (int j = i + 1; j < n; ++j) {
  13.             int diff = a[j] - a[i];
  14.             b ^= (diff | (diff - 1)) - diff;
  15.         }
  16.         s ^= b;
  17.     }
  18.     return s;
  19. }
  20.  
  21.  
  22. int main() {
  23.     freopen("input.txt", "rt", stdin);
  24.    
  25.     int n;
  26.     scanf("%d", &n);
  27.    
  28.     std::vector<int> a(n); for (auto& it : a) scanf("%d", &it);
  29.    
  30.     std::sort(a.begin(), a.end());
  31.    
  32.     printf("%d", solve_slow(a));
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement