답안 #1023414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023414 2024-07-14T18:04:50 Z NintsiChkhaidze XOR Sum (info1cup17_xorsum) C++17
45 / 100
450 ms 40304 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,inf = 1e9;
int a[N];
pii 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] & ((1<<(0 + 1)) - 1)),j};
  sort(arr+1,arr+n+1);

  int ans=0,add=0;
  for (int i = 0; i <= 30; i++){
    int m = n;
    for (int j = 1; j <= n; j++){
      int bb = ((a[arr[j].s] >> i) & 1);
      if(bb > 0) fix[j] = 1,arr[++m] = arr[j];
    }
 
    int idx = 0;
    for (int j = 1; j <= m; j++){
      if (!fix[j]) b[++idx] = arr[j];
    }
 
    for (int j = 1; j <= n; j++){
      int x = b[j].s;
      arr[j] = {(a[x] & ((1<<(i + 1)) - 1)),x};
      fix[j] = 0;
    }

    int cnt = 0;
    int r0 = 0,r1 = 0,r2 = 0;
 
    for (int j = n; j >= 1; j--){
        while (r0 + 1 <= n && (((arr[j].f + arr[r0 + 1].f) >> i) & 3) <= 0) r0++;
        while (r1 + 1 <= n && (((arr[j].f + arr[r1 + 1].f) >> i) & 3) <= 1) r1++;
        while (r2 + 1 <= n && (((arr[j].f + arr[r2 + 1].f) >> 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:32:13: warning: unused variable 'add' [-Wunused-variable]
   32 |   int ans=0,add=0;
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4440 KB Output is correct
2 Correct 4 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 450 ms 40304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 450 ms 40304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4440 KB Output is correct
2 Correct 4 ms 2648 KB Output is correct
3 Correct 90 ms 6744 KB Output is correct
4 Correct 89 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4440 KB Output is correct
2 Correct 4 ms 2648 KB Output is correct
3 Incorrect 450 ms 40304 KB Output isn't correct
4 Halted 0 ms 0 KB -