vijosP1195 "very male and female" program
Links: https://vijos.org/p/1195
Ideas
The number is poor.
There must be an equal number of males and females in the interval between two points with the same number of differences.
So far to I of 1 is sum1,0 for SUM0, then the number of the difference is T, with the L [t] array record difference T appears the leftmost point, compared to ans.
Code
1#include <iostream>2#include <cstdio>3 using namespacestd;4 5 Const intMAXN =200000+Ten;6 Const intn=100000+2;7 intL[maxn],r;8 intN;9 TenInlineintRead_int () { One CharC=GetChar (); A while(!isdigit (c)) c=GetChar (); - intx=0; - while(IsDigit (c)) { thex=x*Ten+c-'0'; -C=GetChar (); - } - returnx; + } - intMain () { +n=read_int (); A intans=0; at intsum0=0, sum1=0; -l[0+n]=0; - for(intI=1; i<=n;i++) { - intx=read_int (); - if(x) sum1++;Elsesum0++; - intt=sum1-sum0+N; in if((t-n) &&!l[t]) l[t]=i; -Ans=max (ans,i-l[t]); to } +cout<<ans; - return 0; the}
vijosP1195 "very male and female" program