Submission #1326814

#TimeUsernameProblemLanguageResultExecution timeMemory
1326814al95ireyizXOR Sum (info1cup17_xorsum)C++20
100 / 100
1174 ms31732 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], u[maxn], a_[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;
  // 30nlogn -> tle
  // 30n elemek lazimdi
  // 010, 011, 100, 101
  // 011, 101, 1010, 1100
  // eslinde bele baxanda gormek olur ki elebil 1 olanlari elimizle secib axira qoyuruq
  // onda b[i]-de indexleri saxliyaq ve herdefe indexleri sadece 2 qrupa bolub her qrup icinde
  // indexlerin bir birine positionlarini eyni saxlamaqla 1 olanlari qabaga qoyaq
  for(ll i = 1; i <= n; i ++) b[i] = i;
  for(ll bt = 0; bt <= 30; bt ++){
    ll ind = 0;
    for(ll i = 1; i <= n; i ++) if(!(a[b[i]] & (1ll << bt))) u[++ ind] = b[i];
    for(ll i = 1; i <= n; i ++) if(a[b[i]] & (1ll << bt)) u[++ ind] = b[i];
    for(ll i = 1; i <= n; i ++) b[i] = u[i], a_[i] = a[i] & ((1ll << (bt + 1)) - 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(a_[b[x_l]] + a_[b[y]] < l and x_l <= n) x_l ++;
      while(a_[b[x_r]] + a_[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(a_[b[x_l]] + a_[b[y]] < l and x_l <= n) x_l ++;
      while(a_[b[x_r]] + a_[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...