题解 CF1466E 【Apollo versus Pan】
do_while_true · · 题解
\mathcal{Translate}
题目链接
给定
\mathcal{Solution}
先交换求和号之后就可以拆位求了。
先拆位预处理后就能快速计算里面两个式子了。
时间复杂度
\mathcal{Code}
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#define ll long long
#define re register
#define int long long
inline int Max(int x, int y) { return x > y ? x : y; }
inline int Min(int x, int y) { return x < y ? x : y; }
inline int Abs(int x) { return x < 0 ? ~x + 1 : x; }
inline int read() {
int r = 0; bool w = 0; char ch = getchar();
while(ch < '0' || ch > '9') {
if(ch == '-') w = 1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
r = (r << 3) + (r << 1) + (ch ^ 48);
ch = getchar();
}
return w ? ~r + 1 : r;
}
#undef int
const int N = 5e5 + 10;
const ll mod = 1e9 + 7;
int T, n;
ll a[N], sum[N], ans;
signed main() { T = read(); while(T--) {
n = read();
for(int i = 1; i <= n; ++i) a[i] = read();
for(int i = 0; i <= 60; ++i) sum[i] = 0; ans = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 0; j <= 60; ++j)
if((1ll << j) & a[i])
++sum[j];
}
for(int i = 1; i <= n; ++i) {
ll sum1 = 0, sum2 = 0;
for(int j = 0; j <= 60; ++j) {
ll ss = (1ll << j) % mod;
if((1ll << j) & a[i]) sum1 += sum[j] * ss % mod, sum2 += n * ss % mod;
else sum2 += sum[j] * ss % mod;
sum1 %= mod, sum2 %= mod;
}
ans = (ans + sum1 * sum2 % mod) % mod;
}
printf("%lld\n", ans);
}
return 0;
}