题目链接
题目思路
可以转化问题为(largesum_{i=1}^{n} (x_i&x_1+x_i&x_2+...+x_i&x_n)*(x_i|x_1+x_i|x_2+...+x_i|x_n))
然后根据套路二进制求贡献即可
代码
#include<bits/stdc++.h>
#define fi first
#define se second
#define debug cout<<"I AM HERE"<<endl;
using namespace std;
typedef long long ll;
const int maxn=5e5+5,inf=0x3f3f3f3f,mod=1e9+7;
const double eps=1e-6;
int n;
ll a[maxn];
int cnt[100];
signed main(){
int _;scanf("%d",&_);
while(_--){
memset(cnt,0,sizeof(cnt));
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
for(int j=0;j<=60;j++){
if(a[i]&(1ll<<j)){
cnt[j]++;
}
}
}
ll ans=0;
for(int i=1;i<=n;i++){
ll temp1=0,temp2=0;
for(int j=0;j<=60;j++){
if(a[i]&(1ll<<j)){
temp1=(temp1+cnt[j]*((1ll<<j)%mod))%mod;
temp2=(temp2+n*((1ll<<j)%mod))%mod;
}else{
temp2=(temp2+cnt[j]*((1ll<<j)%mod))%mod;
}
}
ans=(ans+temp1*temp2)%mod;
}
printf("%lld
",ans);
}
return 0;
}