https://codeforces.com/contest/1101/problem/G
一个有n个数字的数组a[],将区间分成尽可能多段,使得段之间的相互组合异或和不等于零
#include<bits/stdc++.h>
#define ll long long
#define M 200005
using namespace std;
ll a[M],sum=0,n,BS[50];
ll sol(){
for(int i=1;i<=n;i++){
for(int j=30;j>=0;j--){
if(a[i]>>j&1){
if(!BS[j]){BS[j]=a[i];break;}
a[i]^=BS[j];
}
}
}
ll ans=0;
for(int i=0;i<=30;i++)ans+=(BS[i]>0);
return ans;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
sum^=a[i];
}
if(sum==0)cout<<-1;
else cout<<sol();
}
Educational Codeforces Round 58 (Rated for Div. 2) G 线性基
原文:https://www.cnblogs.com/VIrtu0s0/p/10631617.html