Codeforces Round #305 (Div. 1) B. Mike and Feet

Source: Internet
Author: User

Codeforces Round #305 (Div. 1) B. Mike and Feet

Mike is the president of country What-The-Fatherland. There areNBears living in this country besides Mike. All of them are standing in a line and they are numbered from 1NFrom left to right.I-Th bear is exactlyAIFeet high.

A group of bears is a non-empty contiguous segment of the line. the size of a group is the number of bears in that group. the strengthof a group is the minimum height of the bear in that group.

Mike is a curious to know for eachXSuch that 1 limit ≤ limitXLimit ≤ limitNThe maximum strength among all groups of sizeX.

Input

The first line of input contains integerN(1 digit ≤ DigitNLimit ≤ limit 2 × hour 105), the number of bears.

The second line containsNIntegers separated by space,A1, bytes,A2, middle..., middle ,...,AN(1 digit ≤ DigitAIMemory ≤ memory 109), heights of bears.

Output

PrintNIntegers in one line. For eachXFrom 1N, Print the maximum strength among all groups of sizeX.

Sample test (s) input
101 2 3 4 5 4 3 2 1 6
Output

6 4 4 3 3 2 2 1 1

You can use a monotonous stack to maintain a stack and record minmum (minimum value of the interval) and count (total length of the interval ).

 

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Define deusing namespace std; # define maxn 200060int ans [maxn]; struct node {int count, minmum;} stack [maxn]; int main () {int n, m, I, j, top, count, B; while (scanf (% d, & n )! = EOF) {memset (ans, 0, sizeof (ans); top = 0; for (I = 1; I <= n; I ++) {scanf (% d, & B); count = 0; while (top> 0 & stack [top]. minmum> = B) {stack [top]. count + = count; count = stack [top]. count; if (ans [count]
     
      
0) {stack [top]. count + = count; count = stack [top]. count; if (ans [count]
      
       
/* The ans [I] calculated here is the minimum value of the continuous length range with I, but this minimum value is the maximum value of all consecutive lengths with I, if ans [I + 1] is larger than ans [I], ans [I] can be updated to ans [I + 1]. if the maximum value of the minimum value of an I + continuous number interval is B, remove a number and the maximum value of the continuous number interval with the length of I is B. */
for(i=n;i>=2;i--){if(ans[i]>ans[i-1]){ans[i-1]=ans[i];}}for(i=1;i<=n-1;i++){printf(%d ,ans[i]);}printf(%d,ans[i]);}return 0;}


 

Related Article

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.