传送门
文章目录
- 题意:
- 思路:
题意:
思路:
完全想不到容斥啊,看了半天也没看懂渍渍渍。
定义f[i]f[i]f[i]表示iii的超集个数,那么选择的方案就是2f[i]−12^{f[i]}-12f[i]−1了,因为不能一个不选所以要减去空集。
显然f[i]f[i]f[i]可以通过高维前缀和预处理出来,现在考虑如何计算答案。
答案应该包含在f[0]f[0]f[0]内,但是有重复元素,所以考虑容斥来消去,具体的就是ans=∑i=0n(−1)i中1的个数2f[i]−1ans=\sum _{i=0}^{n}(-1)^{i中1的个数}2^{f[i]-1}ans=∑i=0n(−1)i中1的个数2f[i]−1,转化成人话就是:全部为000的个数−-−至少一个为111的个数+++至少两个为111的个数…
// Problem: D. Jzzhu and Numbers
// Contest: Codeforces - Codeforces Round #257 (Div. 1)
// URL: https://codeforces.com/problemset/problem/449/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=4000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n;
int a[N];
int c[N];LL qmi(LL a,LL b) {LL ans=1;while(b) {if(b&1) ans=ans*a%mod;a=a*a%mod;b>>=1;}return ans%mod;
}int get(int x) {int cnt=0;while(x) cnt+=x%2,x/=2;if(cnt&1) return -1;else return 1;
}int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",&a[i]),c[a[i]]++;for(int i=0;i<20;i++) {for(int j=0;j<1<<20;j++)if(j>>i&1) {(c[j^(1<<i)]+=c[j])%=mod;}}LL ans=0;for(int i=0;i<1<<20;i++) {ans+=(((qmi(2,c[i])-1)*get(i))%mod+mod)%mod;ans%=mod; }printf("%lld\n",ans);return 0;
}
/**/