#711
Unrated
Min Max Subarrays
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

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

You are given a length-NN integer array a1,a2,,aNa_1,a_2,\dots,a_N (2N106,1aiN2\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)/2N(N+1)/2 contiguous subarrays of aa.

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)(10, 3) is replaced by min(10,3)=3\min(10, 3)=3 and (4,3)(4, 3) is replaced by max(4,3)=4\max(4, 3)=4.

입력

The first line contains NN.

The second line contains a1,a2,,aNa_1,a_2,\dots,a_N.

출력

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

예제 입력 1

2
2 1

예제 출력 1

4

예제 입력 2

3
3 1 3

예제 출력 2

12

예제 입력 3

4
2 4 1 3

예제 출력 3

22

점수

Inputs 4-5: N100N\le 100Inputs 6-7: N5000N\le 5000Inputs 8-9: max(a)10\max(a)\le 10Inputs 10-13: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.