QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 256 MB Total points: 100

#10964. Min Max Subarrays

Statistics

Note: The time limit for this problem is 3s, 1.5x the default.

You are given a length-$N$ integer array $a_1,a_2,\dots,a_N$ ($2\le N\le 10^6, 1\le a_i\le N$). Output the sum of the answers for the subproblem below over all $N(N+1)/2$ contiguous subarrays of $a$. Given a nonempty list of integers, alternate the following operations (starting with the first operation) until the list has size exactly one. Replace two consecutive integers in the list with their minimum.Replace two consecutive integers in the list with their maximum. Determine the maximum possible value of the final remaining integer. For example, [4, 10, 3] -> [4, 3] -> [4] [3, 4, 10] -> [3, 10] -> [10] In the first array, $(10, 3)$ is replaced by $\min(10, 3)=3$ and $(4, 3)$ is replaced by $\max(4, 3)=4$.

Input Format

The second line contains $a_1,a_2,\dots,a_N$.

Output Format

The sum of the answer to the subproblem over all subarrays.

Sample Data

Sample Input

2
2 1

Sample Output

4

Sample Input 2

3
3 1 3

Sample Output 2

12

Sample Input 3

4
2 4 1 3

Sample Output 3

22

Sample Explanation

Consider the subarray $[2, 4, 1, 3]$. Applying the first operation on (1, 3), our new array is $[2, 4, 1]$. Applying the second operation on (4, 1), our new array is $[2, 4]$. Applying the third operation on (2, 4), our final number is $2$. It can be proven that $2$ is the maximum possible value of the final number.

Constraints

  • Inputs 4-5: $N\le 100$
  • Inputs 6-7: $N\le 5000$
  • Inputs 8-9: $\max(a)\le 10$
  • Inputs 10-13: No additional constraints.
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.