RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0660

Min Max Subarrays

Diamond V 다이아몬드 V
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

*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.

  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\).

Problem credits: Benjamin Qi

제약

SCORING

  • 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.

Problem credits: Benjamin Qi

입력 형식

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
출력
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
출력
12
예제 3
입력
4
2 4 1 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.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > February > Platinum

태그

평가 및 의견

Min Max Subarrays

개요
출제자 난이도 Diamond V 다이아몬드 V 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Min Max Subarrays

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8