状态压缩,比较相同状态取数
https://ac.nowcoder.com/acm/contest/13175/E
#include<bits/stdc++.h>
#define inf 1e18
#define ll long long
#define MAX 1000001
const ll N = 1e6+7;
const ll M = 3e6+7;
const ll mod = 1e9+7;
using namespace std;
int n,a[N];
int point[N];
int mp[M];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
for(int i=1;i<=n;++i){
point[i]=point[i-1];
if((point[i]>>a[i])&1) point[i]-=(1ll<<a[i]);
else point[i]+=(1ll<<a[i]);
}
for(int i=0;i<=n;++i){
mp[point[i]]++;
}
ll ans=0;
for(int i=0;i<=n;++i){
mp[point[i]]--;
ans+=mp[point[i]];
}
printf("%lld
",ans);
return 0;
}