The goal is to partition an array of length $n$ into the maximum number of contiguous segments $k$ such that the bitwise OR of the XOR sums of these segments is $\le x$.
Key logic:
- Use prefix XORs: Let $sum_i$ be the XOR sum of the first $i$ elements. The XOR sum of a segment $[l, r]$ is $sum_r \oplus sum_{l-1}$.
- The condition $(sum_{r_1} \oplus sum_{l_1-1}) \mid (sum_{r_2} \oplus sum_{l_2-1}) \mid \dots \mid (sum_{r_k} \oplus sum_{l_k-1}) \le x$ can be simplified by observing that if we pick $l_1=1$ (so $sum_{l_1-1}=0$), the condition relates to the prefix XORs at the boundaries of the partitions.
- To maximize $k$, iterate through each bit $k$ of $x$. If the $k$-th bit is 1, you can potentially create a tighter bound by setting that bit to 0 and all lower bits to 1.
- For a target mask $xx$, a prefix XOR $sum_i$ is a valid partition boundary if $(sum_i \mid xx) == xx$.
- The final prefix XOR $sum_n$ must satisfy the condition $(sum_n \mid xx) == xx$ for the partition to be valid.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,l,r) for(int i = l;i<=r;i++)
void solve(){
int n,x;
cin>>n>>x;
vector<int> vec(n+5);
rep(i,1,n){
cin>>vec[i];
vec[i] ^= vec[i-1]; // Prefix XOR
}
int ans = -1;
rep(k,0,32){
int xx = x;
int cnt = 0;
if((x>>k) & 1){
xx -= 1<<k;
xx |= ((1<<k)- 1);
}
// The total XOR sum must fit within the mask xx
if((vec[n] | xx) != xx) {continue;}
rep(i,1,n){
if((vec[i] | xx) == xx){
cnt++;
ans = max(ans,cnt);
}
}
}
if(ans > 0) cout<<ans<<'\n';
else cout<<-1<<'\n';
}
signed main(){
int T = 1;
cin>>T;
while(T--){
solve();
}
return 0;
}