该题要求将一个数组分成若干个段,保证段本身,段与段之间的异或都不为0的最大段数量
由于段与段之间的异或和不为0,因此,可判断,各段的异或值是线性无关的,且根据题目要求各段的异或值是不为0的,因此,数组中线性相关的值必须放在同一段里另外加任意值。以保证段的值不为0
应该敏锐的察觉到,上述特性与线性基的特性高度重合,因此,题目所求的值即为线性基的大小
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<bitset>
#include<cmath>
#include<array>
#include<atomic>
#include<sstream>
#include<stack>
#include<iomanip>
//#include<bits/stdc++.h>
//#define int ll
#define pb push_back
#define endl '\n'
#define x first
#define y second
#define Endl endl
#define pre(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,b,a) for(int i=b;i>=a;i--)
#define si(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define ss(x) scanf("%s", x);
#define YES {puts("YES");return;}
#define NO {puts("NO"); return;}
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
typedef pair<char, int> PCI;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<ll, ll> PLL;
const int N = 200010, M = 2 * N, B = N, MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
int n, m, k;
int a[N], p[35];
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lowbit(ll x) { return x & -x; }
ll qmi(ll a, ll b, ll mod) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
inline void init() {}
bool insert(int x) {
bool res = false;
rep(i, 30, 0)
{
if (((x >> i) & 1)==0)continue;
if (p[i]==0) {
p[i] = x; res = true;
break;
}
x ^= p[i];
}
return res;
}
void slove()
{
cin >> n;
pre(i, 1, n)cin >> a[i];
int t=0;
pre(i, 1, n) {
insert(a[i]);
t ^= a[i];
}
if (!t) { cout << -1 << endl; return; }
else {
int cnt = 0;
pre(i, 0, 30)if (p[i])cnt++;
cout << cnt << Endl;
}
}
signed main()
{
int _;
//si(_);
_ = 1;
init();
while (_--)
{
slove();
}
return 0;
}