思路:思路和上一篇一模一样哒~(这里就不多解释啦)
ACcode:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2e5+10;
int n,a[N],f[N];
int main()
{ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);cin>>n;for(int i=1;i<=n;i++)cin>>a[i];int res=1e5,ans=0;for (int i = 1; i <= n; i ++ ){if(a[i]==1)res++;else res--;if(!f[res])f[res]=i;else ans=max(ans,i-f[res]);if(res==1e5)ans=i;}cout<<ans<<"\n";return 0;
}
over~