以 P3917 为例。
#include<bits/stdc++.h>
#define u unsigned
using namespace std;
u read()
{
char ch=getchar();
u s=0;
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s;
}
const int w=32;
const int k=16;
const int U=1<<k;
u a[100005];
int s[w];
void solve(int n)
{
static int t[U<<1];
int i,j,l;
for(i=0;i<w/k;i++)
{
memset(t,0,sizeof(t));
for(j=1;j<=n;j++)
t[(a[j]&U-1)+U]++,a[j]>>=k;
for(j=U-1;j>1;j--)
t[j]=t[j<<1]+t[j<<1|1];
for(j=0;j<k;j++)
for(l=(1<<k-j)+1;l<(1<<k-j+1);l+=2)
s[i*k+j]+=t[l];
}
}
int main()
{
int n=read(),i;
long long sum=0;
for(i=1;i<=n;i++)
a[i]=read()^a[i-1];
solve(n);
for(i=0;i<w;i++)
sum+=(1ll<<i)*s[i]*(n-s[i]+1);
cout<<sum;
}