Test instructions
n matrices in a row, n<=2e5, height of hei[i], width of 1
For some successive matrices, the size of the matrix is the number of matrices, and the strength of the matrix is the height of the lowest height in these matrices.
Request: For each x Such this 1≤ x ≤ n the maximum strength among all groups of size x.
For each matrix, we first find out the l,r of this matrix
L represents the subscript to the left of the matrix that is closer to its matrix than its
R represents the subscript to the right of the matrix that is closer to its matrix than its
That is, within the interval (l,r), the strength equals the height of the matrix.
Note: The 2 matrices of l,r are not included
The value of the l,r can be calculated using the DP
After l,r, only need to make these matrices as small as the height to the big sort again,
Then iterate over and update the ANS array continuously
#include <cstdio>#include<algorithm>#include<cstring>using namespacestd;Const intMAXN =200000+5;intANS[MAXN];structnode{intHei,l,r;}; Node NODE[MAXN];BOOLcmp (Node x,node y) {returnX.hei <Y.hei;}voidsolve () {intN; scanf ("%d",&N); N++; for(intI=1; i<n;i++) {scanf ("%d",&Node[i].hei); } node[0].hei =0; Node[n].hei=0; for(intI=1; i<n;i++) {NODE[I].L= i-1; while(I >0&& Node[node[i].l].hei >=Node[i].hei) {NODE[I].L=NODE[NODE[I].L].L; } } for(inti=n-1;i>0; i--) {NODE[I].R= i +1; while(I < n && Node[node[i].r].hei >=Node[i].hei) {NODE[I].R=NODE[NODE[I].R].R; }} memset (ans,-1,sizeofans); Sort (Node+1, node+n,cmp); for(intI=1; i<n;i++){ intpos = NODE[I].R-NODE[I].L-1; Ans[pos]=Max (Ans[pos],node[i].hei); } for(inti=n-1;i>0; i--) {Ans[i]= Max (ans[i],ans[i+1]); } for(intI=1; i<n-1; i++) printf ("%d", Ans[i]); printf ("%d\n", ans[n-1]); return ;}intMain () {solve (); return 0;}
CF 547B. Mike and Feet DP