#P9152. 待黑白分明
待黑白分明
Background
.
Problem Description
The city where Shiro lives can be viewed as consecutive points on a number line. The height of point is , and it is guaranteed that is a permutation of .
In the year 3202, technology is highly advanced, and wormhole train technology has been developed. There are types of trains. The -th type of train passes through all positions whose height is at least . Each train line is bidirectional, meaning you can take the train from left to right or from right to left.
Shiro wants to travel around the city. She defines a set of positions to be valid if and only if, after sorting the positions in by height, each pair of adjacent positions in this order can be traveled between directly by taking one type of train without stopping in between.
She will ask you queries. In each query, you are given , and you need to tell Shiro the number of valid sets such that the heights of all positions are within , modulo .
Input Format
The first line contains two positive integers .
The second line contains positive integers, representing .
The next lines each contain two positive integers , representing the height interval of the -th query.
Output Format
Output lines. Each line contains one non-negative integer, representing the answer.
5 3
2 4 5 1 3
3 5
1 5
1 4
5
12
6
Hint
Sample Explanation
Explanation for the first query:
The valid height sets are: .
Constraints
For of the testdata, , is a permutation, and .
| Subtask | Special Property | Score | ||
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | A | |||
| 4 | B | |||
| 5 | ||||
| 6 | ||||
Special Property A: .
Special Property B: is chosen uniformly at random from all permutations of length .
Translated by ChatGPT 5