-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe.cpp
99 lines (92 loc) · 2 KB
/
e.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// template.cpp : Defines the entry point for the console application.
//
#include <climits>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <list>
#include <tuple>
#include <ctime>
#include <cassert>
#include <cstring>
using namespace std;
//type shortcuts
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef vector<double> VD;
typedef vector<VD> VVD;
//constants
const ll INF=0x1fffffffffffffff;
const double INFD=1e20;
const double EPS=1e-9;
const double PI = atan(1) * 4;
const ll M = 1000000007;
//for-loop shortcut
#define rng(i,begin,end) for (ll i=begin;i<end;++i)
ll mod(ll x) { return (x > M) ? (x%M) : x; }
ll add(ll a, ll b){return mod(a+b);}
ll mul(ll a, ll b){return mod(a*b);}
//scanf shortcuts
ll scan() {ll r;scanf("%lld",&r);return r;}
void scanstr(char *buf){scanf("%s",buf);}
#define pow2(x) (1LL<<(x))
#define getbit(x,i) (((x)>>(i))&1LL)
ll f[60];
ll X[500000];
ll pow2[60];
ll work(ll n, ll m){
rng(k,0,m){
f[k]=0;
rng(i,0,n){
f[k]+=getbit(X[i],k);
}
f[k]=mul(f[k],pow2[k]);
}
ll ans=0;
rng(i,0,n){
ll term1=0;
rng(k,0,m){
term1=add(term1,mul(getbit(X[i],k),f[k]));
}
ll term2=mul(n,mod(X[i]));
rng(k,0,m){
term2=add(term2,mul(f[k],(1-getbit(X[i],k))));
}
ans=add(ans,mul(term1,term2));
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
pow2[0] = 1;
for (int i = 1; i < 60; i++) {
pow2[i] = mul(pow2[i-1],2);
}
ll tn;
cin>>tn;
rng(ti,0,tn){
ll n;
cin>>n;
ll w=0;
rng(i,0,n){
cin>>X[i];
w=max(w,(64ll-__builtin_clzll(X[i])));
}
ll ans=work(n,w);
cout<<ans<<endl;
}
return 0;
}