Submission #1023378

# Submission time Handle Problem Language Result Execution time Memory
1023378 2024-07-14T17:22:49 Z NintsiChkhaidze XOR Sum (info1cup17_xorsum) C++17
45 / 100
1600 ms 20560 KB
#include <bits/stdc++.h>
#include <ostream>
#define pb push_back
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
#define ll long long
#define left h*2,l,(l + r)/2
#define right h*2+1,(l + r)/2 + 1,r
#define int ll
using namespace std;
 
const int N = 1e6 + 5,inf = 1e9;
int a[N],arr[N];

signed main() {
  ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
  
  int n;
  cin>>n;

  for (int i = 1; i <= n; i++){
    cin >> a[i];
  }
  
  int ans=0,add=0;
  for (int i = 0; i <= 30; i++){
    for (int j = 1; j <= n; j++)
      arr[j] = (a[j] & ((1<<(i + 1)) - 1));

    sort(arr+1,arr+n+1);
    vector <pair <pii,int>  > v;
    
    for (int j = 1; j <= n; j++){
      int sum = (arr[j] + arr[n]);
      sum >>= i;
      sum &= 3;

      if (v.size() && v.back().s == sum) v.back().f.s += 1;
      else {
        v.pb({{j,j},sum});
      }
    }

    int cnt = 0,add = 0;
    for (int j = n; j >= 1; j--){
      vector <pair<pii,int> > vnew;

      for (int k = 0; k < v.size(); k++){
        int l = v[k].f.f,r = v[k].f.s,val = v[k].s;

        while (r + 1 <= n){
          int sum = (((arr[r + 1] + arr[j]) >> i) & 3);
          if (sum == val) r += 1;
          else break;
        }

        while (l <= n){
          int sum = (((arr[l] + arr[j]) >> i) & 3);
          if (sum != val) l += 1;
          else break;
        }

        if (l <= r){
          vnew.pb({{l,r},val});
        }
      }

      sort(vnew.begin(),vnew.end());
      int id = 1,k = 0;
      vector <pair<pii,int> > vec;
      while (k < vnew.size()){
        if (id == vnew[k].f.f){
          vec.pb(vnew[k]);
          id = vnew[k].f.s + 1;
          k++;
        }else{
          int l = id,r = id,val = (((arr[id] + arr[j]) >> i) & 3);

          while (r + 1 <= n){
            int sum = (((arr[r + 1] + arr[j]) >> i) & 3);
            if (sum == val) r += 1;
            else break;
          }
          vec.pb({{l,r},val});
          id = r + 1;
        }
      }

      sort(vec.begin(),vec.end());
      for (int k = 0; k <vec.size(); k++){
        int s = vec[k].s;
        if (s == 3 || s == 1){
          int l = vec[k].f.f,r = vec[k].f.s;
          l = max(l,j);
          cnt += max(0LL,(r - l + 1));
        }
      }

      int s = (((arr[j]*2) >> i) & 3);
      v = vec;
    }

    if (cnt & 1) ans |= (1LL<<i);
  }

  cout<<ans;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:50:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |       for (int k = 0; k < v.size(); k++){
      |                       ~~^~~~~~~~~~
xorsum.cpp:73:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |       while (k < vnew.size()){
      |              ~~^~~~~~~~~~~~~
xorsum.cpp:92:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |       for (int k = 0; k <vec.size(); k++){
      |                       ~~^~~~~~~~~~~
xorsum.cpp:4:11: warning: unused variable 'second' [-Wunused-variable]
    4 | #define s second
      |           ^~~~~~
xorsum.cpp:101:11: note: in expansion of macro 's'
  101 |       int s = (((arr[j]*2) >> i) & 3);
      |           ^
xorsum.cpp:46:17: warning: unused variable 'add' [-Wunused-variable]
   46 |     int cnt = 0,add = 0;
      |                 ^~~
xorsum.cpp:27:13: warning: unused variable 'add' [-Wunused-variable]
   27 |   int ans=0,add=0;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2392 KB Output is correct
2 Correct 23 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1665 ms 20560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1665 ms 20560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2392 KB Output is correct
2 Correct 23 ms 2396 KB Output is correct
3 Correct 586 ms 7512 KB Output is correct
4 Correct 552 ms 7708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2392 KB Output is correct
2 Correct 23 ms 2396 KB Output is correct
3 Execution timed out 1665 ms 20560 KB Time limit exceeded
4 Halted 0 ms 0 KB -