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

33761번 - Lazy Sort 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB115555.556%

문제

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

입력

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

예제 출력 1

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

예제 출력 2

89

힌트

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2025 US Open Contest > Platinum 2번

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

출처

대학교 대회

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

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