Submission #1076385

# Submission time Handle Problem Language Result Execution time Memory
1076385 2024-08-26T13:28:36 Z LucasLe XOR Sum (info1cup17_xorsum) C++17
100 / 100
569 ms 38352 KB
#include <bits/stdc++.h>

#define                int  long long
#define                pii  pair<int, int>
#define                 fi  first
#define                 se  second
#define                 ld  long double
#define                 vi  vector<int>
#define                vii  vector<vector<int>>
#define             all(v)  (v).begin(), (v).end()
#define       rep(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i)
#define       per(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i)

using namespace std;

const int MOD = 1e9 + 7;

int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}

int mul(int a, int b) {
  (a *= b) %= MOD;
  return a;
}

int bin_pow(int x, int y) {
  int res=1;
  while(y){if(y&1)res=res*x%MOD;x=x*x%MOD;y>>=1;}
  return res;
}

const int INF = 1e17;
const int maxn = 2e6 + 5;
const int LG = 29;

int N, ans;
int a[maxn + 5], c[maxn + 5];

void solve(int tc) {
  cin >> N;
  rep(i, 1, N) cin >> a[i];
  rep(j, 0, LG) {
    vi b0, b1;
    rep(i, 1, N) {
      if (a[i] & (1ll << j)) b1.push_back(a[i]);
      else b0.push_back(a[i]);
    }
    rep(i, 1, N) {
      if (i <= (int)b0.size()) {
        a[i] = b0[i - 1];
      } else {
        a[i] = b1[i - (int)b0.size() - 1];
      }
      c[i] = (a[i] & ((1ll << (j + 1)) - 1));
    }
    int pj = N, pk = N, pl = N;
    rep(i, 1, N) {
      pj = max(pj, i); pk = max(pk, i); pl = max(pl, i);
      while (pj >= i && c[i] + c[pj] >= (1ll << j)) pj--;
      while (pk >= i && c[i] + c[pk] >= (1ll << (j + 1))) pk--;
      while (pl >= i && c[i] + c[pl] >= (1ll << j) + (1ll << (j + 1))) pl--;
      if ((N - pl + pk - pj) & 1) ans ^= (1ll << j);
    }
  }
  cout << ans;
}

///  011
/// 1001
///  110
///  110

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  int tc = 1;
//  cin >> tc;
  for (int i = 1; i <= tc; ++i) {
    solve(i);
  }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 604 KB Output is correct
2 Correct 4 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 432 ms 35012 KB Output is correct
2 Correct 359 ms 31688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 432 ms 35012 KB Output is correct
2 Correct 359 ms 31688 KB Output is correct
3 Correct 454 ms 37648 KB Output is correct
4 Correct 397 ms 38352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 604 KB Output is correct
2 Correct 4 ms 2396 KB Output is correct
3 Correct 51 ms 6548 KB Output is correct
4 Correct 48 ms 6408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 604 KB Output is correct
2 Correct 4 ms 2396 KB Output is correct
3 Correct 432 ms 35012 KB Output is correct
4 Correct 359 ms 31688 KB Output is correct
5 Correct 454 ms 37648 KB Output is correct
6 Correct 397 ms 38352 KB Output is correct
7 Correct 51 ms 6548 KB Output is correct
8 Correct 48 ms 6408 KB Output is correct
9 Correct 569 ms 37084 KB Output is correct
10 Correct 523 ms 37520 KB Output is correct
11 Correct 515 ms 38032 KB Output is correct