Links: Http://codeforces.com/problemset/problem/497/B
This kind of question examines is the basic skill. Like my basic 0 喳喳 can only be stuck here ...
Train of thought: N range is 10^5, must find out Nlogn algorithm is OK. Enumerate T, and then use two points to find the solution. Clever ~ ~ Good topic like a, although not do ~ ~ ~
Code:
/************************************************author:ltwycreated time:2014 December 18 Thursday 16:28 12 seconds file Name : 1.cpp*************************************************/#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<stack>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<time.h>using namespacestd;intN;inta[101000];intsum1[101000];intsum2[101000];p Air<int,int> p[100100];intGet_next (intSintStinted) { if(Sum1[ed]-sum1[st-1] <s && sum2[ed]-sum2[st-1] <s)return-1; intL = St, r =Ed; intID =Ed; while(L <=r) {intMid = (l+r) >>1; if(Sum1[mid]-sum1[st-1] < s&& Sum2[mid]-sum2[st-1] <s) {L= mid+1; } Else{ID=mid; R= Mid-1; } } returnID;}intMain () {//freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout);scanf ("%d", &N); for(intI=1; i<=n; i++) {scanf ("%d", &A[i]); } memset (Sum1,0,sizeof(SUM1)); memset (sum2,0,sizeof(sum2)); intT1 =0+ s2 =0; for(inti =1; i<=n; i++) { if(A[i] = =1) T1++; if(A[i] = =2) T2++; Sum1[i]=T1; Sum2[i]=T2; } intCNT =0; intW1 =0; intW2 =0; BOOLFlag; for(ints=1; s<=n; s++) {W1=0; W2=0; Flag=false; if(Sum1[n] < s && Sum2[n] <s) Break; intpos =1; intLast =0; while(Pos <=N) {inttemp =Get_next (S, POS, n); if(temp = =-1) {flag=true; Break; } if(A[temp] = =1) {W1++; Last=1; } Else{W2++; Last=2; } POS= temp+1; } if(flag)Continue; if(W1 = =W2)Continue; if(W1 > w2&& last = =2) Continue; if(W2 > w1&& last = =1) Continue; P[cnt++] =Make_pair (Max (W1, W2), s); } printf ("%d\n", CNT); Sort (p, p+CNT); for(intI=0; i<cnt; i++) printf ("%d%d\n", P[i].first, P[i].second); return 0;}
Codeforces 497B Tennis Game thinking + two points ~