Apollo versus Pan
题目:
思路:求f(j), 可以预处理 第i为上1的个数,贡献即为 (1<<i )*cnt[i]。
g(j)同理。
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf=2e18+100;
const int maxn=5e5+100;
const int mod=1e9+7;
int a[maxn],cnt[100];
signed main()
{
IOS
int tt;
cin>>tt;
while(tt--)
{
int n;
cin>>n;
memset(cnt,0,sizeof cnt);
for(int i=1; i<=n; i++)
{
cin>>a[i];
for(int j=0; j<=61; j++)
{
if(((a[i]>>j)&1)==1)
{
cnt[j]++;
}
}
}
int ans=0;
for(int i=1; i<=n; i++)
{
int tp1=0,tp2=0;
for(int j=0; j<=61; j++)
{
if(((a[i]>>j)&1)==1)
{
tp1+=cnt[j]*((1LL<<j)%mod);
tp1%=mod;
}
}
for(int j=0; j<=61; j++)
{
if(((a[i]>>j)&1)==1)
{
tp2+=n*((1LL<<j)%mod);
tp2%=mod;
}
else
{
tp2+=cnt[j]*((1LL<<j)%mod);
tp2%=mod;
}
}
ans=(ans+tp1*tp2%mod)%mod;
}
cout<<ans<<"\n";
}
}