It seems impossible to start, to write out the equation calm down:
Conditions for the interval $ [i, j] $, to meet the requirements of:
$sum[i][1]-sum[j-1][1]=sum[i][2]-sum[j-1][2]$
$sum[i][1]-sum[j-1][1]=sum[i][3]-sum[j-1][3]$
...
$sum[i][1]-sum[j-1][1]=sum[i][k]-sum[j-1][k]$
Wherein $ sum [i] [j] $ represents the number of $ [1, i] within the interval characteristic $ $ $ appears J
Was put together under the same label:
$sum[j-1][2]-sum[j-1][1]=sum[i][2]-sum[i][1]$
$sum[j-1][3]-sum[j-1][1]=sum[i][3]-sum[i][1]$
...
$sum[j-1][k]-sum[j-1][1]=sum[i][k]-sum[i][k]$
Found satisfied as long as the $ sum [i] [p] -sum [i] [1] = sum [j] [p] -sum [j] [1], \ forall p \ in [1, k] $
So directly engage in a $ map $ maintenance on the line, I feel the state $ hash $ is not stable ah, so a direct enumeration judge put forward a structure like
Note that the prefix and so remember to put $ 0 $ Join $ map $!
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<map> using namespace std; typedef long long ll; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*f; } const int N=1e5+7; int n,K,ans; struct dat{ int a[31]; dat () { memset(a,0,sizeof(a)); } inline dat F() { dat res; for(int i=1;i<=K;i++) res.a[i]=a[i]-a[1]; return res; } inline bool operator < (const dat &tmp) const { for(int i=1;i<=K;i++) if(a[i]!=tmp.a[i]) return a[i]<tmp.a[i]; return 0; } }C[N],sum; map <dat,int> mp; int main() { n=read(),K=read(); int a; for(int i=1;i<=n;i++) { a=read(); for(int j=1;j<=K;a>>=1,j++) C[i].a[j]=a&1; } mp[sum.F()]=1; for(int i=1;i<=n;i++) { for(int j=1;j<=K;j++) sum.a[j]+=C[i].a[j]; dat p=sum.F(); if(mp[p]) ans=max(ans,i-(mp[p]-1)); else mp[p]=i+1; } printf("%d\n",ans); return 0; }