#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define per(a,b,c) for(int a=b;a>=c;--a)
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
int n;
int a[N],pre[N];
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n;
rep(i,1,n){
cin>>a[i];
pre[i]=a[i];
}
if(n>=60) {cout<<1<<‘\n‘;return 0;}
rep(i,2,n) pre[i]=pre[i-1]^a[i];
int ans=INF;
rep(i,1,n){
rep(j,i,n){
rep(k,j+1,n){
rep(p,k,n){
if((pre[j]^pre[i-1])>(pre[p]^pre[k-1])){
ans=min(ans,j-i+p-k);
}
}
}
}
}
if(ans==INF) ans=-1;
cout<<ans<<‘\n‘;
return 0;
}
Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2) D. XOR-gun (二进制,异或,前缀和)
原文:https://www.cnblogs.com/lr599909928/p/14059174.html