D. XOR-gun(Constructive &Xor)

考虑每个数的最高位,若存在连续3个最高位相同的,则可以操作前两个,答案为1.

根据鸽巢原理,当超过 2 × ( l o g 2 1 0 9 + 1 ) = 60 2\times (log_210^9+1)=60 2×(log2109+1)=60个则必然答案为1。

接下来我们只需考虑暴力。

考虑答案,显然 a n s i = a l ⊕ a l + 1 ⋯ ⊕ a r ans_i=a_l\oplus a_{l+1}\dots \oplus a_r ansi=alal+1ar

考虑最后答案, a n s i > a n s i + 1 ans_i>ans_{i+1} ansi>ansi+1

a l ⊕ a l + 1 ⋯ ⊕ a m > a m + 1 ⊕ a m + 2 ⋯ ⊕ a r a_l\oplus a_{l+1}\dots \oplus a_m >a_{m+1}\oplus a_{m+2}\dots \oplus a_{r} alal+1am>am+1am+2ar

暴力取最值即可,时间复杂度: O ( n 3 ) O(n^3) O(n3)

// Problem: D. XOR-gun
// Contest: Codeforces - Technocup 2021 - Elimination Round 2
// URL: https://codeforces.ml/problemset/problem/1415/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Date: 2021-07-27 11:09:19
// --------by Herio--------

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
const int N=1e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define IOS ios::sync_with_stdio(false),cin.tie(0) 
void Print(int *a,int n){
	for(int i=1;i<n;i++)
		printf("%d ",a[i]);
	printf("%d\n",a[n]); 
}
int n,a[66],s=inf;
int main(){
	scanf("%d",&n);
	if(n>60) return puts("1"),0;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1,x;i<n;i++){
		x=0;
		for(int j=i,y;j;j--){
			x^=a[j],y=0;
			for(int k=i+1;k<=n;k++){
				y^=a[k];
				if(x>y){
					s=min(s,k-j-1);
				}
			}
		}
	}
	if(s==inf) s=-1;printf("%d\n",s);
	return 0;
}