「EZEC-6」分组 题解
do_while_true · · 题解
官方题解。
Subtask
Subtask
Subtask
Subtask
Subtask
Subtask
至此,问题解决。
#include<iostream>
#include<cstdio>
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
#define ull unsigned long long
char buf[1<<21],*p1=buf,*p2=buf;
template <typename T>
inline T& read(T& r) {
r = 0; bool w = 0; char ch = getchar();
while(ch < '0' || ch > '9') w = ch == '-' ? 1 : 0, ch = getchar();
while(ch >= '0' && ch <= '9') r = r * 10 + (ch ^ 48), ch = getchar();
return r = w ? -r : r;
}
const int N = 1000100;
int n, ans;
ull f[64], all;
signed main() {
read(n);
for(int i = 1; i <= 61; ++i) f[i] = 1ll << (i-1);
for(int i = 1; i <= n; ++i) {
ull x; read(x);
if(!x) {
++ans;
continue;
}
all |= x;
int p = __builtin_ffsll(x); ull t = f[p] | x;
if(t == f[p]) continue;
for(int j = 1; j <= 61; ++j)
if((1ll << (j-1)) & t)
t |= f[j];
for(int j = 1; j <= 61; ++j)
if((1ll << (j-1)) & t)
f[j] |= t;
}
for(int i = 1; i <= 61; ++i)
if((1ll << (i-1)) & all)
if(f[i]) {
++ans; ull t = f[i];
for(int j = 1; j <= 61; ++j)
if((1ll << (j-1)) & t)
f[j] = 0;
}
printf("%d\n", ans);
return 0;
}