-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path053-apollo-versus-pan.cpp
More file actions
94 lines (93 loc) · 2.15 KB
/
Copy path053-apollo-versus-pan.cpp
File metadata and controls
94 lines (93 loc) · 2.15 KB
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
/*
* Apollo versus Pan [1466E]
* Problem: https://codeforces.com/problemset/problem/1466/E
* Verdict: ACCEPTED Solved: 2022-09-13
* Language: C++20 (GCC 11-64)
* Runtime: 1513 ms Memory: 0 KB
* Tags: bitmasks, brute force, math
* Author: BidoTeima
* Source: https://codeforces.com/contest/1466/submission/172085602
*/
/// isA AC
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void moo(string filename);
void ACPLS(string str = "")
{
if(str=="NOF")return;
if(str.size())
moo(str);
else{
#ifndef ONLINE_JUDGE
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
#endif
}
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void moo(string fileName){
freopen((fileName+".in").c_str(),"r",stdin);
freopen((fileName+".out").c_str(),"w",stdout);
}
#define tc \
int tttttt/*,subtask*/; \
cin >> tttttt/* >> subtask*/; \
while (tttttt--)
#define sumrange(l, r, arr) (l == 0 ? arr[r] : arr[r] - arr[l - 1])
#define all(v) v.begin(), v.end()
ll mod = 1e9 + 7;
int f[60][60];
ll calc(int i, int j, ll n){
__int128 ans = 0;
ans = __int128(__int128(1ll<<i)*__int128(1ll<<j))%mod;
ans*=f[i][i];
ans%=mod;
ans*=(f[i][i]-f[min(i,j)][max(i,j)]);
ans%=mod;
ans*=f[j][j];
ans%=mod;
__int128 ans2 = 0;
ans2=__int128(__int128(1ll<<i)*__int128(1ll<<j));
ans2%=mod;
ans2*=f[i][i];
ans2%=mod;
ans2*=f[min(i,j)][max(i,j)];
ans2%=mod;
ans2*=n;
ans2%=mod;
return (ans+ans2)%mod;
}
int main()
{
ACPLS("");
tc{
for(uint8_t i = 0; i < 60; i++){
for(uint8_t j = 0; j < 60; j++){
f[i][j]=0;
}
}
int n;
ll v;
cin>>n;
int sz = n;
while(n--){
cin>>v;
for(uint8_t i = 0; i < 60; i++){
for(uint8_t j = i; j < 60; j++){
f[i][j]+=(v&(1ll<<i))&&(v&(1ll<<j));
}
}
}
ll ans=0;
for(uint8_t i = 0; i < 60; i++){
for(uint8_t j = 0; j < 60; j++){
ans+=calc(i,j,sz);
ans%=mod;
}
}
cout<<ans<<'\n';
}
}