#P5469. [NOI2019] 机器人
[NOI2019] 机器人
Description
Little R likes studying robots.
Recently, Little R developed two new types of robots, P-type robots and Q-type robots. Now he wants to test their moving abilities. The test is done on pillars arranged in a line from left to right, numbered in order. The height of pillar is a positive integer . Robots can only move between adjacent pillars, that is: if a robot is currently on pillar , it can only try to move to pillar and pillar .
In each test, Little R chooses a starting point and places both types of robots on pillar . Then they move according to their own rules.
The P-type robot keeps moving to the left, but it cannot move onto a pillar that is higher than the starting pillar . More specifically, the P-type robot stops at pillar if and only if both of the following conditions hold:
-
or .
-
For every with , we have .
The Q-type robot keeps moving to the right, but it can only move onto pillars that are lower than the starting pillar . More specifically, the Q-type robot stops at pillar if and only if both of the following conditions hold:
-
or .
-
For every with , we have .
Now, Little R can set the height of each pillar. The selectable height range for pillar is , that is, . Little R hopes that no matter where the test starting point is chosen, the absolute value of the difference between the numbers of pillars moved over by the two robots is always less than or equal to . He wants to know how many height-setting schemes satisfy this requirement. Little R considers two schemes different if and only if there exists some such that the height of pillar is different in the two schemes. Please output the number of valid schemes modulo .
Input Format
The first line contains a positive integer , representing the number of pillars.
The next lines each contain two positive integers , representing the minimum and maximum height of pillar .
Output Format
Output one line with one integer, the answer modulo .
5
3 3
3 3
3 4
2 2
3 3
1
Hint
More Samples
You can get more samples through the additional files.
Sample 2
See robot/robot2.in and robot/robot2.ans in the additional files.
Sample 3
See robot/robot3.in and robot/robot3.ans in the additional files.
Sample 4
See robot/robot4.in and robot/robot4.ans in the additional files.
Explanation for Sample 1
There are two possible pillar height settings:
-
Heights:
3 2 3 2 3. If the starting point is set to , theP-type robot will stop at pillar , moving across pillars. TheQ-type robot stops at pillar , moving across pillars. This does not satisfy the condition. -
Heights:
3 2 4 2 3. In this case, no matter where the starting point is chosen, the condition is satisfied. Details are shown in the table below:
::cute-table{tuack}
| Starting index | P-type robot | Q-type robot |
|---|---|---|
| Stops at pillar , moves across | Stops at pillar , moves across | |
| Stops at pillar , moves across | ||
| Stops at pillar , moves across | Stops at pillar , moves across | |
| Stops at pillar , moves across | ||
| Stops at pillar , moves across | Stops at pillar , moves across | |
Constraints
For all testdata: , .
The detailed limits for each test point are shown in the table below:
::cute-table{tuack}
| Test point ID | Special property | |
|---|---|---|
| None. | ||
| ^ | ||
Translated by ChatGPT 5
京公网安备 11011102002149号