Submission #1326813

#TimeUsernameProblemLanguageResultExecution timeMemory
1326813al95ireyizXOR Sum (info1cup17_xorsum)C++20
32 / 100
1108 ms16076 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define len(x) (ll)x.size()
const ll inf = 1e9, infl = 1e18;
const ll MOD = 1e9 + 7;
const ll maxn = 1e6 + 5;
ll n, m, k = 0;

ll a[maxn], b[maxn];
void _() {
  // j-ci biti 1 olan pair sayini tapmaq ucun ele x, y cutlerini tapmaliyiq ki

  // 2 ^ j <= b[x] + b[y] < 2 ^ (j + 1) veya 
  // 2 ^ (j + 1) + 2 ^ j <= b[x] + b[y] < 2 ^ (j + 2)
  // harda ki b[i] = a[i] & (2 ^ (j + 1) - 1)

  cin >> n;
  for(ll i = 1; i <= n; i ++){
    cin >> a[i];
  }
  ll cv = 0;
  for(ll bt = 0; bt <= 20; bt ++){
    for(ll i = 1; i <= n; i ++){
      b[i] = a[i] & ((1ll << (bt + 1)) - 1);
    }

    sort(b + 1, b + n + 1);

    ll x_l, x_r, l, r, c = 0;

    // 2 ^ j <= b[x] + b[y] < 2 ^ (j + 1)
    l = 1ll << bt;
    r = 1ll << (bt + 1);
    
    x_l = x_r = 1;
    for(ll y = n; y >= 1; y --){
      while(b[x_l] + b[y] < l and x_l <= n) x_l ++;
      while(b[x_r] + b[y] < r and x_r <= n) x_r ++;

      c += max(0ll, x_r - max(x_l, y));
    }

    // 2 ^ (j + 1) + 2 ^ j <= b[x] + b[y] < 2 ^ (j + 2)
    l = (1ll << bt) + (1ll << (bt + 1));
    r = 1ll << (bt + 2);

    x_l = x_r = 1;
    for(ll y = n; y >= 1; y --){
      while(b[x_l] + b[y] < l and x_l <= n) x_l ++;
      while(b[x_r] + b[y] < r and x_r <= n) x_r ++;

      c += max(0ll, x_r - max(x_l, y));
    }

    if(c & 1) cv |= 1ll << bt;
  }
  cout << cv << '\n';
}
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  ll t = 1;
  // cin >> t;
  while(t --) _();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...