답안 #1017646

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017646 2024-07-09T09:18:20 Z KindaNameless XOR Sum (info1cup17_xorsum) C++14
100 / 100
643 ms 53200 KB
#include <bits/stdc++.h>
 
#define ll long long
#define endl '\n'
#define For(i,l,r) for(int i=l;i<=r;i++)
#define ForD(i,r,l) for(int i=r;i>=l;i--)
#define REP(i,l,r) For(i,l,r-1)
#define PER(i,r,l) ForD(i,r-1,l)
#define ff first
#define ss second
#define pb emplace_back
#define all(x) x.begin(),x.end()
#define All(x,n) x+1,x+1+n
#define Alll(x,n) x,x+n
#define sz(a) (signed)a.size()
 
#ifdef NCGM
#include"debug.h"
#else 
#define debug(...) "fr";
#endif
 
using namespace std;
 
ll ans=0;
const int N=1e6+2;
int n,a[N];
pair<ll,int> t[N],t1[N],t2[N];
int cnt(int x) {
    int l=1,r=n;
    int res=0;
    while(l<r) {
        if (t[l].ff+t[r].ff<=x) {
            res+=(r-l);
            l++;
        } else r--;
    }
    For(i,1,n) if (t[i].ff*2<=x) res++;
    return res;
}
int cntr(int l,int r) {
    if (r<l) return 0;
    return cnt(r)-cnt(l-1);
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    For(i,1,n) cin >> a[i];
    int cur=0;
    For(i,1,n) t[++cur]=make_pair(a[i]%2,i);
    sort(t+1,t+1+n);
    For(i,0,29) {
        if (i>0) {
            int x=0,y=0;
            For(j,1,n) {
                if ((a[t[j].ss]>>i)&1) t1[++x]=make_pair(t[j].ff+(1<<i),t[j].ss);
                else t2[++y]=t[j];
            }
            For(j,1,y) t[j]=t2[j];
            For(j,1,x) t[j+y]=t1[j];
        }
        ll tmp=cntr((1LL<<i),(1LL<<(i+1))-1);
        tmp+=cntr((1LL<<i+1)+(1LL<<i),(1LL<<i+2)-1);
        if (tmp%2) ans+=(1LL<<i);
    }
    cout << ans;
    return 0;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:63:26: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   63 |         tmp+=cntr((1LL<<i+1)+(1LL<<i),(1LL<<i+2)-1);
      |                         ~^~
xorsum.cpp:63:46: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   63 |         tmp+=cntr((1LL<<i+1)+(1LL<<i),(1LL<<i+2)-1);
      |                                             ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 48208 KB Output is correct
2 Correct 432 ms 46256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 48208 KB Output is correct
2 Correct 432 ms 46256 KB Output is correct
3 Correct 515 ms 50512 KB Output is correct
4 Correct 491 ms 49124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 61 ms 9564 KB Output is correct
4 Correct 62 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 459 ms 48208 KB Output is correct
4 Correct 432 ms 46256 KB Output is correct
5 Correct 515 ms 50512 KB Output is correct
6 Correct 491 ms 49124 KB Output is correct
7 Correct 61 ms 9564 KB Output is correct
8 Correct 62 ms 9564 KB Output is correct
9 Correct 631 ms 53200 KB Output is correct
10 Correct 616 ms 53076 KB Output is correct
11 Correct 643 ms 53004 KB Output is correct