绝望 发表于 2019-07-26 更新于 2019-08-01 分类于 题解 Problem’s Website] Hopeless Solution Code123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#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++