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

Min Max Subarrays II

Platinum II 플래티넘 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

You are given integers \(N,Q\) \((1 \leq N, Q \leq 2 \cdot 10^5)\) and \(Q\)
constraints represented by four integers \(t_i,l_i,r_i,k_i\)
\((1 \leq t_i \leq 2, 1 \leq l_i \leq r_i \leq N, 0 \leq k_i \leq 10^9,\) all
\(k_i\) are distinct\().\)

Construct an array \(a\) consisting of \(N\) integers between \(0\) and \(10^9\) such
that for all \(1 \leq i \leq Q\), \(\min a[l_i ... r_i]=k_i\) if \(t_i=1\) and
\(\max a[l_i ... r_i]=k_i\) if \(t_i=2\). If multiple valid arrays exist, print any.
If no valid array exists, print \(-1\).

Problem credits: Charlie Yang

제약

SCORING

  • Inputs 3-4: \(N,Q\le 100\) and all \(t_i\) within the same test case are equal
  • Inputs 5-6: all \(t_i\) within the same test case are equal
  • Inputs 7-10: \(N,Q\le 100\)
  • Inputs 11-14: No additional constraints.

Problem credits: Charlie Yang

입력 형식

The first line contains an integer \(T\) (\(1 \leq T \leq 10^4\)) representing the
number of independent test cases.

For each test case, the first line contains two integers \(N, Q\).

The next \(Q\) lines each contain 4 integers \(t_i\) \(l_i\) \(r_i\) \(k_i\).

It is guaranteed that neither the sum of \(N\) nor the sum of \(Q\) over all test
cases exceed \(2 \cdot 10^5\).

출력 형식

For each test case, if a valid array exists, output \(N\) space-separated integers
\(a_1\dots a_N\) on a new line. Otherwise, print \(-1\).

예제 1
입력
3
2 2
1 1 2 1
1 1 2 2
2 2
1 1 2 1
1 2 2 2
4 1
2 2 4 3
출력
-1
1 2
0 3 0 0
설명

In the first test case, the answer is \(-1\) because the minimum value of the
array cannot be both \(1\) and \(2\) at the same time.

In the second test case, \(a[1 ... 2]\) has a minimum of \(1\) at \(a[1]\) in the sample output, satisfying
the first constraint. Since \(a[2] = 2\), the second constraint is also
satisfied.

In the third test case, there are multiple solutions. For instance, the array
\([4, 3, 2, 1]\) would also be accepted.

예제 2
입력
4
2 2
1 1 2 1
2 1 2 2
3 2
1 1 2 3
2 2 3 1
5 2
1 1 2 3
1 4 5 2
4 4
1 1 4 1
1 2 3 2
2 1 2 5
2 3 4 6
출력
1 2
-1
3 3 0 2 2
1 5 2 6
설명

In the second test case, the array \([3, 5, 1]\) satisfies the first constraint
but not the second constraint. Contrarily, the array \([3, 1, 1]\) satisfies the
second constraint but not the first constraint. It can be proven that no array
can satisfy both constraints at the same time, hence the answer is \(-1\).

For all other test cases, it can be proven that the constructed array satisfies
all \(Q\) constraints.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2025-2026 > Third Contest > Platinum

태그

평가 및 의견

Min Max Subarrays II

개요
출제자 난이도 Platinum II 플래티넘 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Min Max Subarrays II

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