Xor Sum 4
分析,给n个数,求任意两个数的异或和之和。看贡献度,贡献度为每个数的第i位为1的总和*0的总和。(异或的性质)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+50;
const int N=2e6+15;
const ll mod =1e9+7;
const int inf=2e9+7;
ll a[N];
int main()
{
int n;
scanf("%d",&n);
ll ans=0;
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
for(int i=0;i<=62;i++)
{
ll x=0;
for(int j=1;j<=n;j++)
{
if(a[j]>>i &1)
{
x++;
}
}
ll now=x*(n-x)%mod;
for(int j=1;j<=i;j++)
{
now=now*2%mod;
}
ans+=now;
ans%=mod;
}
printf("%lld\n",ans);
return 0;
}