#P14008. 「florr IO Round 1」序列游戏
「florr IO Round 1」序列游戏
Description
Please note the time limit for this problem.
For a sequence , we define its weight as the sum of the squares of the lengths of all maximal color segments. A color segment is defined as an interval where all elements are equal. A maximal color segment is a color segment that cannot be contained within any longer color segment.
Given a sequence of length , where each is an integer chosen uniformly at random from the interval , compute the expected value of the weight over all possible sequences , modulo .
Input Format
The first line contains a single integer , representing the length of the sequence.
The next lines each contain two integers and , indicating the random range for .
Output Format
Output a single integer, representing the expected weight over all possible sequences .
2
1 1
1 1
4
2
1 2
1 2
3
5
1 3
2 4
5 5
2 5
1 5
776412281
Hint
Sample Explanation
Sample Explanation #1
Obviously, in this case , so the expected weight is .
Sample Explanation #2
In this case, the four possible sequences are $a = \{1, 1\}, a = \{1, 2\}, a = \{2, 1\}, a = \{2, 2\}$. For and , the weight is , and for and , the weight is . Therefore, the expected weight is .
Data Range
This problem uses bundled testing.
| Subtask | Score | Special Properties | ||
|---|---|---|---|---|
| 1 | None | |||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | Data is random | |||
| 6 | None | |||
Translated by ChatGPT 4.1
京公网安备 11011102002149号