답안 #1076382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1076382 2024-08-26T13:27:53 Z vjudge1 XOR Sum (info1cup17_xorsum) C++17
100 / 100
522 ms 47040 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);
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2648 KB Output is correct
2 Correct 3 ms 2672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 392 ms 42484 KB Output is correct
2 Correct 345 ms 39712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 392 ms 42484 KB Output is correct
2 Correct 345 ms 39712 KB Output is correct
3 Correct 428 ms 43952 KB Output is correct
4 Correct 394 ms 42684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2648 KB Output is correct
2 Correct 3 ms 2672 KB Output is correct
3 Correct 54 ms 7556 KB Output is correct
4 Correct 54 ms 7432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2648 KB Output is correct
2 Correct 3 ms 2672 KB Output is correct
3 Correct 392 ms 42484 KB Output is correct
4 Correct 345 ms 39712 KB Output is correct
5 Correct 428 ms 43952 KB Output is correct
6 Correct 394 ms 42684 KB Output is correct
7 Correct 54 ms 7556 KB Output is correct
8 Correct 54 ms 7432 KB Output is correct
9 Correct 520 ms 47040 KB Output is correct
10 Correct 522 ms 46292 KB Output is correct
11 Correct 518 ms 46464 KB Output is correct