#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
//#define int long long
#define double long double
const int mxn=1e6+5,inf=1e9,minf=-1e9;
int lg=0;
int n;
void print(int x){
for(int j=0;j<=3;j++){
if(x&(1LL<<j))cout<<1;
else cout<<0;
}
cout<<'\n';
}
void bruteforcecheck(){
int x=1000;
for(int k=0;k<lg;k++){
vector<int>v;
for(int i=0;i<10000;i++){
int a=x+i;
if((a&(1LL<<k)))v.pb(i);
}
int cnt=1,gap=0;
for(int i=1;i<v.size();i++)if(v[i]-v[i-1]!=1){
cnt++;
if(gap&&gap!=v[i]-v[i-1])assert(0);
gap=v[i]-v[i-1];
}
if(v.size()){
cout<<cnt<<' '<<gap<<' '<<v[0]<<' '<<k<<'\n';
}
}
}
struct fen{
int fwk[mxn+10];
vector<int>keep;
void update(int pos,int val){
pos++;
keep.pb(pos);
for(int i=pos;i<=n;i+=(i&-i))fwk[i]+=val;
}
int qry(int pos){
pos++;
if(pos==0)return 0;
int sum=0;
for(int i=pos;i>0;i-=(i&-i))sum+=fwk[i];
return sum;
}
void re(){
for(auto j:keep){
for(int i=j;i<=n;i+=(i&-i))fwk[i]--;
}
keep.clear();
}
}t;
int st[mxn+10][2];
int between(int x,int l,int r){
if(l<=r)return (l<=x&&x<=r);
return (l<=x||x<=r);
}
int P[mxn+10],C[mxn+10];
int32_t main(){
fastio
cin>>n;
vector<int>v(n);
P[0]=1;
int mx=0;
for(int i=1;i<=lg;i++)P[i]=P[i-1]*2;
for(int i=0;i<n;i++)cin>>v[i],mx=max(mx,v[i]);
for(int j=0;j<=29;j++)if(mx&(1<<j))lg=j;
lg++;
sort(all(v));
int sz=1,gap=1,cnt=0,bro=0;
ll ans=0;
int mod=sz+gap,tmp=inf;
vector<int>vm;
for(int i=0;i<n;i++)st[i][0]=inf;
for(int k=0;k<=lg;k++){
sz=(1LL<<k);
cnt=0;
bro=0;
mod=sz+gap;
vm.clear();
for(int i=0;i<n;i++)vm.pb(v[i]%mod);
sort(all(vm));
for(int i=0;i<n;i++){
st[i][(k%2)^1]=inf;
st[i][k%2]=min(st[i][k%2],(1<<k));
if(v[i]&(1<<k))st[i][(k%2)^1]=st[i][k%2];
else st[i][(k%2)^1]=st[i][k%2]+(1<<k);
t.update(lb(all(vm),v[i]%mod)-vm.begin(),1);
if(v[i]&(1LL<<k))C[i]++;
int l=st[i][k%2];
if(v[i]&(1<<k)){
l+=(1<<k);
st[i][k%2]=0;
}
int r=l+sz-1;
l%=mod,r%=mod;
if(l<=r){
bro+=t.qry(upper_bound(all(vm),r)-vm.begin()-1)-t.qry(lb(all(vm),l)-vm.begin()-1);
}
else{
swap(l,r);
l++,r--;
bro-=t.qry(upper_bound(all(vm),r)-vm.begin()-1)-t.qry(lb(all(vm),l)-vm.begin()-1);
bro+=i+1;
}
//for(int j=0;j<=i;j++)cnt+=between(v[j]%mod,l,r);
}
gap+=sz;
if(bro%2)ans+=(1LL<<k);
t.re();
}
cout<<ans<<'\n';
}
/*
1 0 0 1 1 0 0 1 1
starting sz=1,gap=2
for each k sz=2^k,gapk=gapk-1+2^k-1
starting num=x;
cnt+=valj<i{
valj>=x
valj mod (sz+gapk) is between [x mod (sz+gapk),x+sz mod (sz+gapk)]
}
how to find starting num? dp log(n)
*/
Compilation message
xorsum.cpp: In function 'void bruteforcecheck()':
xorsum.cpp:54:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int i=1;i<v.size();i++)if(v[i]-v[i-1]!=1){
| ~^~~~~~~~~
xorsum.cpp: In function 'int32_t main()':
xorsum.cpp:103:17: warning: variable 'cnt' set but not used [-Wunused-but-set-variable]
103 | int sz=1,gap=1,cnt=0,bro=0;
| ^~~
xorsum.cpp:105:17: warning: unused variable 'tmp' [-Wunused-variable]
105 | int mod=sz+gap,tmp=inf;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
6648 KB |
Output is correct |
2 |
Correct |
28 ms |
6480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1613 ms |
33160 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1613 ms |
33160 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
6648 KB |
Output is correct |
2 |
Correct |
28 ms |
6480 KB |
Output is correct |
3 |
Correct |
878 ms |
3364 KB |
Output is correct |
4 |
Correct |
797 ms |
4132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
6648 KB |
Output is correct |
2 |
Correct |
28 ms |
6480 KB |
Output is correct |
3 |
Execution timed out |
1613 ms |
33160 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |