This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define pb push_back
#define pii pair<int,int>
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << " " << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T x, S... y){cerr << x << ", ";_do(y...);}
#else
#define bug(...) 49
#endif
const int maxn=1000005;
int n,a[maxn],ans,cur;
vector<int> vec[2];
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> n;
rep(n) cin >> a[i];
rep(n) vec[a[i]&1].pb(a[i]);
rep1(j,30){
int cnt=0;
bug(j);
for(auto i: vec[0]) bug(i);
for(auto i: vec[1]) bug(i);
rep1(k,2){
cur=sz(vec[k])-1;
rep(sz(vec[k])){
while(cur>=0&&((vec[k][i]+vec[k][cur])>>j&1)) cur--;
cnt+=sz(vec[k])-1-cur;
//if((sz(vec[k])-1-cur)&1) ans^=pow2(j);
}
}
rep(n) if((a[i]<<1)&pow2(j)) cnt++;
cnt/=2;
if(cnt&1) ans^=pow2(j);
cur=0;
rep3(i,sz(vec[0])-1,0){
while(cur<sz(vec[1])&&((vec[0][i]+vec[1][cur])>>j&1)) cur++;
if(cur&1) ans^=pow2(j);
}
vector<int> tmp[2];
for(auto i: vec[0]) if(!(i&pow2(j+1))) tmp[0].pb(i);
for(auto i: vec[1]) if(!(i&pow2(j+1))) tmp[0].pb(i);
for(auto i: vec[0]) if(i&pow2(j+1)) tmp[1].pb(i);
for(auto i: vec[1]) if(i&pow2(j+1)) tmp[1].pb(i);
vec[0]=tmp[0],vec[1]=tmp[1];
}
cout << ans << "\n";
}
Compilation message (stderr)
xorsum.cpp: In function 'int main()':
xorsum.cpp:21:18: warning: statement has no effect [-Wunused-value]
21 | #define bug(...) 49
| ^~
xorsum.cpp:36:9: note: in expansion of macro 'bug'
36 | bug(j);
| ^~~
xorsum.cpp:21:18: warning: statement has no effect [-Wunused-value]
21 | #define bug(...) 49
| ^~
xorsum.cpp:37:29: note: in expansion of macro 'bug'
37 | for(auto i: vec[0]) bug(i);
| ^~~
xorsum.cpp:37:18: warning: unused variable 'i' [-Wunused-variable]
37 | for(auto i: vec[0]) bug(i);
| ^
xorsum.cpp:21:18: warning: statement has no effect [-Wunused-value]
21 | #define bug(...) 49
| ^~
xorsum.cpp:38:29: note: in expansion of macro 'bug'
38 | for(auto i: vec[1]) bug(i);
| ^~~
xorsum.cpp:38:18: warning: unused variable 'i' [-Wunused-variable]
38 | for(auto i: vec[1]) bug(i);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |