Submission #886955

# Submission time Handle Problem Language Result Execution time Memory
886955 2023-12-13T08:59:22 Z Zero_OP XOR Sum (info1cup17_xorsum) C++14
77 / 100
1600 ms 14080 KB
#include<bits/stdc++.h>

using namespace std;

#define range(v) begin(v), end(v)
#define compact(v) v.erase(unique(range(v)), end(v))

template<class T> bool minimize(T& a, T b){
  if(a > b) return a = b, true;
  return false;
}

template<class T> bool maximize(T& a, T b){
  if(a < b) return a = b, true;
  return false;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

void Zero_OP(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }

  int ans = 0;
  for(int target = 30; target >= 0; --target){ //last target bits
    for(int i = 0; i < n; ++i){
      a[i] %= (1 << (target + 1));
    }
    sort(range(a));

    ll cur = 0;
    int j = n, k = n, l = n;
    for(int i = 0; i < n; ++i){
      maximize(j, i);
      maximize(k, i);
      maximize(l, i);

      while(i < j and a[i] + a[j - 1] >= (1 << target)) --j;
      while(i < k and a[i] + a[k - 1] > ((1 << (target + 1)) - 1)) --k;
      while(i < l and a[i] + a[l - 1] >= (1 << (target + 1)) + (1 << target)) --l;

      cur += k - j;
      cur += n - l;
    }
    if(cur & 1) ans ^= (1 << target);
  }
  cout << ans << '\n';
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #define task "antuvu"
  if(fopen(task".inp", "r")){
    freopen(task".inp", "r", stdin);
    freopen(task".out", "w", stdout);
  }
  Zero_OP();

  return 0;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:62:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     freopen(task".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
xorsum.cpp:63:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |     freopen(task".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 348 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 747 ms 8792 KB Output is correct
2 Correct 690 ms 8304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 747 ms 8792 KB Output is correct
2 Correct 690 ms 8304 KB Output is correct
3 Correct 1076 ms 11012 KB Output is correct
4 Correct 1048 ms 10580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 348 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 147 ms 1628 KB Output is correct
4 Correct 147 ms 1624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 348 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 747 ms 8792 KB Output is correct
4 Correct 690 ms 8304 KB Output is correct
5 Correct 1076 ms 11012 KB Output is correct
6 Correct 1048 ms 10580 KB Output is correct
7 Correct 147 ms 1628 KB Output is correct
8 Correct 147 ms 1624 KB Output is correct
9 Correct 1592 ms 14080 KB Output is correct
10 Correct 1593 ms 13652 KB Output is correct
11 Execution timed out 1606 ms 13648 KB Time limit exceeded
12 Halted 0 ms 0 KB -