/*
Author: Venn
Time:2023/03/11 14:02:54
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxv = 1<<17;
int sum[maxv],val[maxv];
int vis[maxv];
const int maxn = 1e5+10;
int n,a[maxn];
ll ans;
int bin[19];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
bin[0] = 1;
for(int i=1;i<19;++i) bin[i] = bin[i-1]<<1;
for(int i=1;i<=n;++i) {
cin>>a[i];
sum[a[i]]++;
}
for(int i=1;i<=n;++i) {
int v = 0;
for(int j = 0;j<17;++j) if((a[i]&bin[j]) == 0) v|= bin[j];
if(vis[v]) ans += val[v];
else {
for(int s = v;s;s=v &(s-1)) {
val[v] += sum[s];
}
val[v] += sum[0];
ans += val[v];
vis[v] = 1;
}
}
cout<<ans<<endl;
return 0;
}
位运算 求子集
于 2023-03-13 20:20:21 首次发布