绝望

Problem’s Website]

Solution

Code

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
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define gc getchar()
#define pc(x) putchar(x)
typedef long long ll;
const int Maxn = 1e5 + 10;
ll sc() {
ll xx = 0, ff = 1; char cch = gc;
while(cch < '0' || cch > '9') {
if(cch == '-') ff = -1; cch = gc;
}
while(cch >= '0' && cch <= '9') {
xx = (xx << 1) + (xx << 3) + (cch ^ '0'); cch = gc;
}
return xx * ff;
}
void out(ll x) {
if(x >= 10)
out(x / 10);
pc(x % 10 + '0');
}
ll t, n, h;
ll a[Maxn], f[Maxn];
int main() {
freopen("hopeless.in", "r", stdin);
freopen("hopeless.out", "w", stdout);
t = sc();
while(t--) {
n = sc();
f[h = 0] = 0;
for(int i = 0; i < n; ++i)
a[i] = sc();
std :: sort(a, a + n);
for(int i = 0; i < n; ++i) {
ll last = a[i];
while(a[i] >> (h + 1))
f[++h] = 0;
ll t = 1;
for(int j = 0; j < h; ++j)
if((last >> j) & 1)
t += f[j];
f[h] = std :: max(f[h], t);
}
ll ans = 0;
for(int i = 0; i <= h; ++i)
ans += f[i];
out(ans);
pc('\n');
}
return 0;
}
// !dy

rp++