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

Lazy Sort

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

의견: 0

설명

Farmer John has \(N\) cows (\(2 \leq N \leq 5\cdot 10^6\)) and is attempting to get
them to sort a non-negative integer array \(A\) of length \(N\) by relying on their
laziness. He has a lot of heavy boxes so he lines the cows up one behind
another, where cow \(i+1\) is behind cow \(i\), and gives \(a_i\) boxes to cow \(i\)
(\(0\le a_i\)).

Cows are inherently lazy so they always look to pass their work off to someone
else. From cow \(1\) to \(N-1\) in order, each cow looks to the cow behind them. If
cow \(i\) has strictly more boxes than cow \(i+1\), cow \(i\) thinks this is "unfair"
and gives one of its boxes to cow \(i+1\). This process repeats until every cow is
satisfied.

Farmer John will then note the number of boxes \(b_i\) that each cow \(i\) is
holding and create an array \(B\) out of these values. If \(B = sorted(A)\), then
Farmer John will be happy. Unfortunately, Farmer John forgot all but \(Q\) values
(\(2 \leq Q \leq \min(N, 100)\)) in \(A\). Luckily, those values include the number
of boxes he was going to give to the first and last cow. Each value that FJ
remembers is given in the form \(c_i \; v_i\) representing that \(a_{c_i}=v_i\)
(\(1 \leq c_i \leq N\), \(1\le v_i\le 10^9\)). Determine the number of different
ways the missing values can be filled in so that he will be happy mod \(10^9+7\).

Problem credits: Suhas Nagar

제약

SCORING

  • Inputs 3-4: \(N,v_i\le 100\)
  • Inputs 5-6: \(N\le 100\) and \(v_i \leq 10^6\)
  • Inputs 7-9: \(N \leq 2\cdot 10^5\) and \(v_i \le 10^6\)
  • Inputs 10-12: \(N \leq 2\cdot 10^5\)
  • Inputs 13-15: No additional constraints.

Problem credits: Suhas Nagar

입력 형식

The first line contains two space-separated integers \(N\) and \(Q\) representing
the number of cows and queries respectively.

The next \(Q\) lines contain two space separated integers \(c_i \; v_i\)
representing that cow \(c_i\) initially holds \(v_i\) boxes. It is guaranteed that
\(c_1 = 1\), \(c_Q = N\), and \(c_i < c_{i+1}\) (the order of the cows is strictly
increasing).

출력 형식

Print the number of different ways modulo \(10^9+7\) that values \(a_i\) can be
assigned such that Farmer John will be happy after the cows perform the lazy
sort. It is guaranteed that there will be at least one valid assignment.

예제 1
입력
3 2
1 3
3 2
출력
2
설명

In this example, FJ remembers the values at the ends of the array. The arrays
\([3,2,2]\) and \([3,3,2]\) are the valid arrays that will make FJ happy at the end
of the lazy sorting.

예제 2
입력
6 3
1 1
3 3
6 5
출력
89
문제 정보

riseoj 작성

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

태그

평가 및 의견

Lazy Sort

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

Log in to rate problems.

개별 의견

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

풀이 제출

Lazy Sort

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