[高维前缀和(SOS)][容斥 ]CF449D Jzzhu and Numbers
Little_corn · · 个人记录
link
考虑容斥。
设
分类讨论第
当
如果
本质上就是一个高维前缀和。
那么最后的答案就是至少偶位为
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10, M = 22, MAX = (1 << M), mod = 1e9 + 7;
int n, a[N], f[MAX];
int popcnt(int x){
if(x == 0) return 0;
return popcnt(x >> 1) + (x & 1);
}
int fast_pow(int x, int y){
int ret = 1, base = x;
while(y){
if(y & 1) ret = (ret * base) % mod;
base = (base * base) % mod;
y >>= 1;
}
return ret;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i], f[a[i]]++;
for(int i = 0; i < M; i++){
for(int s = 0; s < MAX; s++){
if((s & (1 << i)) == 0) f[s] = (f[s] + f[s ^ (1 << i)]) % mod;
}
}
int ans = 0;
for(int s = 0; s < MAX; s++){
int cnt = popcnt(s);
ans = (ans + (((cnt & 1) ? (mod - 1) : 1) * (fast_pow(2, f[s]) - 1 + mod)) % mod) % mod;
}
cout << ans;
return 0;
}