CF 547B. Mike and Feet DP

Source: Internet
Author: User

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≤ xn 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.