Test instructions: Give the match situation, output all the s,t that meet the condition, make this game have result.
Enumerate T, then two points to the lower bound of T, and update the boundaries of each inning, judging who wins the current innings. Finally, pay attention to whether the winner of the last inning is the winner of the whole game.
#include <cstdio>#include<cstring>#include<algorithm>#include<map>#include<Set>#include<bitset>#include<queue>#include<stack>#include<string>#include<iostream>#include<cmath>#include<climits>using namespacestd;Const intMAXN =111111;Const intINF =0xFFFFFFF;intSUM1[MAXN];intSUM2[MAXN];intN;intA[MAXN];intErfen1 (intLintRintkey) { intAns =INF; intK =l; while(l<=R) { intMid= (l+r) >>1; if(sum1[mid]-sum1[k-1] = = key) ans=mid; if(sum1[mid]-sum1[k-1] >= key) R = mid-1; ElseL = mid+1; } returnans;}intErfen2 (intLintRintkey) { intAns =INF; intK =l; while(l<=R) { intMid= (l+r) >>1; if(Sum2[mid]-sum2[k-1]==key) ans =mid; if(Sum2[mid]-sum2[k-1]>=key) R = mid-1; ElseL = mid+1; } returnans;}intJudgeintt) { intANS1 =0;intAns2 =0; intL =1; while(l<=N) { intT1 =erfen1 (l,n,t); intt2 =Erfen2 (l,n,t); L= Min (t1,t2) +1; if(l>n+1)return 0; if(T1==t2&&t1==inf)Continue; if(T1<T2) ans1++; Elseans2++; if(L-1==N) { if(ANS1>ANS2&&T1>T2)return 0; if(ANS2>ANS1&&T2>T1)return 0; } } if(ANS1==ANS2)return 0; returnAns1>ans2?ans1:ans2;}structnode{intXinty;};intcmpConstNode &a,ConstNode &b) { returna.x<b.x;} Vector<node >Q;intMain () {CIN>>N; memset (sum2,0,sizeof(sum2)); memset (SUM1,0,sizeof(SUM1)); for(inti =1; i<=n;i++) {scanf ("%d",&A[i]); if(a[i]==1) Sum1[i] =1; ElseSum2[i] =1; } for(inti =1; i<=n;i++) Sum1[i]+=sum1[i-1],sum2[i]+=sum2[i-1]; for(intt =1; t<=n;t++){ intGG =judge (t); if(gg==0)Continue; Node K; k.x= GG; K.Y =T; Q.push_back (k); } sort (Q.begin (), Q.end (), CMP); printf ("%d\n", Q.size ()); for(inti =0; I<q.size (); i++) printf ("%d%d\n", Q[I].X,Q[I].Y); return 0;}
Codeforces Round #283 (Div. 2) D. Tennis Game