outputstandard output
At a break Vanya came to the class and saw an array of
-bit integers
on the board. An integer
is called a
-bit integer if
Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array
and replace the number
with the number
. We define
for a
-bit integer
as the
-bit integer such that all its
bits differ from the corresponding bits of
Vanya does not like the number
Therefore, he likes such segments
such that
, where
denotes the bitwise XOR operation. Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above.
有趣的贪心。
我们发现一段序列的异或前缀和实际只有两种。
因为你选择异或的值是永远一样的。
维护前缀值。
注意
的情况。
#include<bits/stdc++.h>
using namespace std;
#define int long long
map<int,int>mmp;
int pre=0;
int n,k,Mx;
int ans=0;
signed main(){
cin>>n>>k;
Mx=(1<<k)-1;
ans=n*(int)(n+1)/2;
mmp[0]=1;
for(int i=1;i<=n;++i){
int x;
cin>>x;
int A=pre^x;
int B=A^Mx;
if(!mmp.count(A))mmp[A]=0;
if(!mmp.count(B))mmp[B]=0;
if(mmp[A]<=mmp[B]){
ans-=mmp[A];
pre=A;
mmp[A]++;
}
else{
ans-=mmp[B];
pre=B;
mmp[B]++;
}
}
cout<<ans;
}