#724
Unrated
Lazy Sort
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

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

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

Farmer John will then note the number of boxes bib_i that each cow ii is holding and create an array BB out of these values. If B=sorted(A)B = sorted(A), then Farmer John will be happy. Unfortunately, Farmer John forgot all but QQ values (2Qmin(N,100)2 \leq Q \leq \min(N, 100)) in AA. 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 ci  vic_i \; v_i representing that aci=via_{c_i}=v_i (1ciN1 \leq c_i \leq N, 1vi1091\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 109+710^9+7.

입력

The first line contains two space-separated integers NN and QQ representing the number of cows and queries respectively.

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

출력

Print the number of different ways modulo 109+710^9+7 that values aia_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

예제 입력 2

6 3
1 1
3 3
6 5

예제 출력 2

89

점수

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

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.