链接: http://codeforces.com/contest/1054/problem/D
题解:https://www.luogu.org/blog/yqtwrzw/cf1054d-ti-xie
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200005;
ll a1[N],a2[N];
ll k,up,n;
map<ll,ll >cnt;
int main()
{
scanf("%lld %lld",&n,&k);
up=(1<<k)-1;
for(int i=1;i<=n;i++)
{
scanf("%lld",&a1[i]);
}
for(int i=1;i<=n;i++)
{
a2[i]=a1[i]^up;
}
ll res=0;
ll ans=(n+1)*n/2;
cnt[0]=1;
for(int i=1;i<=n;i++)
{
ll x=res^a1[i];
ll y=res^a2[i];
if(cnt[x]>=cnt[y])
{
res=y;
ans-=cnt[res];
cnt[res]++;
}
else
{
res=x;
ans-=cnt[res];
cnt[res]++;
}
}
printf("%lld\n",ans);
return 0;
}