답안 #1023460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023460 2024-07-14T19:06:47 Z NintsiChkhaidze XOR Sum (info1cup17_xorsum) C++17
100 / 100
649 ms 33396 KB
#include <bits/stdc++.h>
#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;
int a[N];
int arr[N],b[N];
bool fix[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];
  }
 
  for (int j = 1; j <= n; j++)
      arr[j] = a[j];
 
  int ans=0,add=0;
  for (int i = 0; i < 30; i++){
    
    // for (int j = 1; j <= n; j++){
    //   b[j] = {(a[j] & ((1LL<<(i + 1)) - 1)),j};
    // }
    // sort(b+1,b+n+1);

    // for (int j = 1; j <= n; j++)
      // cout<<b[j].s<<" ";
    // cout<<endl;

    int idx = 0;
    for (int j = 1; j <= n; j++){
      int bb = ((arr[j] >> i) & 1);
      if (!bb) b[++idx] = arr[j];
    }

    for (int j = 1; j <= n; j++){
      int bb = ((arr[j] >> i) & 1);
      if (bb) b[++idx] = arr[j];
    }

    for (int j = 1; j <= n; j++)
      arr[j] = b[j];

    for (int j = 1; j <= n; j++)
      b[j] = (arr[j] & ((1LL<<(i + 1)) - 1));

    int cnt = 0;
    int r0 = 0,r1 = 0,r2 = 0;
 
    for (int j = n; j >= 1; j--){
        while (r0 + 1 <= n && (((b[j] + b[r0 + 1]) >> i) & 3) <= 0) r0++;
        while (r1 + 1 <= n && (((b[j] + b[r1 + 1]) >> i) & 3) <= 1) r1++;
        while (r2 + 1 <= n && (((b[j] + b[r2 + 1]) >> i) & 3) <= 2) r2++;
 
        int l = max(j,r0 + 1),r = r1;
        cnt += max(0LL,r - l + 1);
 
        l = max(j,r2 + 1),r = n;
        cnt += max(0LL,r - l + 1);
    }
 
    if (cnt & 1) ans |= (1LL<<i);
  }
 
  cout<<ans;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:31:13: warning: unused variable 'add' [-Wunused-variable]
   31 |   int ans=0,add=0;
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 339 ms 23892 KB Output is correct
2 Correct 304 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 339 ms 23892 KB Output is correct
2 Correct 304 ms 22100 KB Output is correct
3 Correct 457 ms 24044 KB Output is correct
4 Correct 421 ms 29520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 71 ms 3676 KB Output is correct
4 Correct 75 ms 3548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 339 ms 23892 KB Output is correct
4 Correct 304 ms 22100 KB Output is correct
5 Correct 457 ms 24044 KB Output is correct
6 Correct 421 ms 29520 KB Output is correct
7 Correct 71 ms 3676 KB Output is correct
8 Correct 75 ms 3548 KB Output is correct
9 Correct 649 ms 33396 KB Output is correct
10 Correct 618 ms 33108 KB Output is correct
11 Correct 613 ms 33228 KB Output is correct