有点数学,(
话说cincout的同步真的差太多了,btw cf竟然也卡cincout
思路:
code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10, M = 70;
const ll mod = 1e9 + 7;
ll a[N], have[M], pow2[M];
inline void init1() {
pow2[0] = 1;
for(int i = 1; i <= 65; ++ i) {
pow2[i] = pow2[i - 1] * 2 % mod;
}
}
inline void init() {
memset(have, 0, sizeof have);
}
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
#endif
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
init1();
int T;
cin >> T;
while(T--) {
init();
ll n;
cin >> n;
for(int i = 1; i <= n; ++ i) {
cin >> a[i];
for(int j = 0; j <= 60; ++ j) {
int u = a[i] >> j & 1;
if(u) ++ have[j];
}
}
ll ans = 0;
for(int i = 1; i <= n; ++ i) {
ll ansOfAnd = 0;
ll ansOfOr = 0;
for(int j = 0; j <= 60; ++ j) {
if(a[i] >> j & 1) {
ansOfAnd = (ansOfAnd + pow2[j] * have[j]) % mod;
ansOfOr = (ansOfOr + pow2[j] * n) % mod;
}
else {
ansOfOr = (ansOfOr + pow2[j] * have[j]) % mod;
}
}
ans = (ans + ansOfAnd * ansOfOr % mod) % mod;
}
cout << ans << endl;
}
}