Logo
(追記) (追記ここまで)

33738번 - Min Max Subarrays 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB105360.000%

문제

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.

  1. Replace two consecutive integers in the list with their minimum.
  2. 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$.

입력

The first line contains $N$.

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

출력

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

제한

예제 입력 1

2
2 1

예제 출력 1

4

The answer for $[2]$ is 2ドル,ドル the answer for $[1]$ is 1ドル,ドル and the answer for $[2, 1]$ is 1ドル$.

Thus, our output should be 2ドル+1+1 = 4$.

예제 입력 2

3
3 1 3

예제 출력 2

12

예제 입력 3

4
2 4 1 3

예제 출력 3

22

Consider the subarray $[2, 4, 1, 3]$.

  1. Applying the first operation on (1, 3), our new array is $[2, 4, 1]$.
  2. Applying the second operation on (4, 1), our new array is $[2, 4]$.
  3. 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.

힌트

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2025 February Contest > Platinum 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /