luogu#P12032. [USACO25OPEN] Lazy Sort P
[USACO25OPEN] Lazy Sort P
题目描述
Farmer John has cows () and is attempting to get them to sort a non-negative integer array of length by relying on their laziness. He has a lot of heavy boxes so he lines the cows up one behind another, where cow is behind cow , and gives boxes to cow ().
Cows are inherently lazy so they always look to pass their work off to someone else. From cow 1 to in order, each cow looks to the cow behind them. If cow has strictly more boxes than cow , cow thinks this is "unfair" and gives one of its boxes to cow . This process repeats until every cow is satisfied.
Farmer John will then note the number of boxes that each cow is holding and create an array out of these values. If , then Farmer John will be happy. Unfortunately, Farmer John forgot all but values () in . 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 representing that (, ). Determine the number of different ways the missing values can be filled in so that he will be happy mod .
输入格式
The first line contains two space-separated integers and representing the number of cows and queries respectively.
The next lines contain two space separated integers representing that cow initially holds boxes. It is guaranteed that , , and (the order of the cows is strictly increasing).
输出格式
Print the number of different ways modulo that values 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.
3 2
1 3
3 2
2
6 3
1 1
3 3
6 5
89
提示
Sample 1 Explanation
In this example, FJ remembers the values at the ends of the array. The arrays and are the valid arrays that will make FJ happy at the end of the lazy sorting.
SCORING:
- Inputs 3-4:
- Inputs 5-6: and
- Inputs 7-9: and
- Inputs 10-12:
- Inputs 13-15: No additional constraints.