hdu5696 interval Value-2016 "Baidu Star"-Preliminary (Astar round2b)

Source: Internet
Author: User

Problem Description

We define "the value of the interval" as the maximum value of the interval (the minimum value).

The left end of an interval is at L, and the right endpoint is R, so the length of the interval is (r−l+1).

Now the smart Jesse wants to know what the value of the interval of the maximum value is for a range of K.

Of course, because the problem is too simple.

We'll have to step up a bit.

What we want to know is, for an interval of length 1∼n, what is the value of the interval of the maximum value respectively?

Sample explanation:

The optimal interval of length 1 is 2−2 answer is 6∗6

The optimal interval of length 2 is 4−5 answer is 4∗4

The optimal interval of length 3 is 2−4 answer is 2∗6

The optimal interval of length 4 is 2−5 answer is 2∗6

The optimal interval of length 5 is 1−5 answer is 1∗6

Input

Multiple sets of test data

The first row is a number n (1≤n≤100000).

The second row n positive integers (1≤ai≤10^9), with the subscript starting at 1.

Due to some kind of force majeure, the AI value will be a randomly generated number within the 1∼10^9. (except for examples)

Output

Outputs a total of n rows, and line I represents the largest interval value in intervals of interval length i.

Sample Input

5

1 6 2) 4 4

Sample Output

36

16

12

12

6

See that red, random? Obviously this is a breakthrough (at that time looked at a lot of people a but did not want to come out

In fact, for random data, some violence is highly efficient.

We enumerate each point as the maximum value of the interval (so that it is larger than this value), and then extend it to both sides, extending the order of the larger to the interval, and updating the answer by doing the edge

Greedy of the correctness of the comparison is obviously, the larger value plus is definitely relatively small value added in excellent, because the maximum value is fixed, we want to let the minimum value of the maximum

1#include <cstdio>2 using namespacestd;3 4 inta[100100],n;5 Long Longans[100100];6 7 voidWork ()8 {9      for(inti =1; I <= n;i++)Tenscanf"%d",&a[i]); One      for(inti =1; I <= n;i++) Aans[i]=0; -      -      for(inti =1; I <= n;i++) the     { -         Long Longmax=a[i],min=A[i]; -         intlen=1, l=i,r=i; -          while(1) +         { -             if(ans[len]<max*min) ans[len]=max*min; +             if(l==1|| a[l-1]>max) A                 if(R==n | | a[r+1]>max) Break; at                 Else -                 { -r++; -len++; -                     if(a[r]<min) min=A[r]; -                 } in             Else -                 if(R==n | | a[r+1]>max) to                 { +l--; -len++; the                     if(a[l]<min) min=A[l]; *                 } $                 ElsePanax Notoginseng                 { -                     if(a[l-1]>a[r+1]) the                     { +l--; Alen++; the                         if(a[l]<min) min=A[l]; +                     } -                     Else $                     { $r++; -len++; -                         if(a[r]<min) min=A[r]; the                     } -                 }Wuyi         } the     } -      Wu      for(inti =1; I <= n;i++) -printf"%i64d\n", Ans[i]); About } $  - intMain () { -      while(SCANF ("%d", &n)! =EOF) - Work (); A     return 0; +}
AC Code

hdu5696 interval Value-2016 "Baidu Star"-Preliminary (Astar round2b)

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.