#P6046. 纯粹容器
纯粹容器
Background
The White King is choosing containers.
Problem Description
The White King made containers and arranged them in a line, numbered from left to right as . The strength of the -th container is , and it is guaranteed that all are distinct. To choose the purest container, the White King performs rounds of operations. In each round, he randomly selects, with equal probability, two containers that are adjacent in position and have not been knocked down, and makes them duel. In a duel, the container with smaller strength will be knocked down and removed from the line.
Obviously, the last remaining container is the one with the greatest strength. However, the poor containers want to know how long they can survive, so they ask you to compute the expected number of rounds each container survives. Output the answers modulo .
The number of rounds a container survives is defined as the largest non-negative integer such that it has not been knocked down after round .
Containers and are adjacent in position if and only if there does not exist a such that and container has not been knocked down.
Input Format
The first line contains an integer .
The second line contains integers , with meanings as described above.
Output Format
Output one line with integers. The -th integer denotes the expected number of rounds that container survives. To avoid floating-point errors, it is guaranteed that the answer can be represented as an irreducible fraction . You only need to output an integer such that .
3
3 1 2
2 0 1
3
1 2 3
499122177 499122177 2
5
1 4 2 3 5
499122178 249561091 665496236 582309207 4
Hint
Sample Explanation
In the first sample, the first container can never be knocked down no matter what happens. The second container will surely be knocked down in the first round. The third container will surely not be knocked down in the first round, and will surely be knocked down in the second round.
The real answers for the second sample are , , .
Constraints
For all test points, it is guaranteed that , , and all are pairwise distinct.
.
.
.
.
No special restrictions.
Hint
If you do not know how to take a fraction modulo a number, you can refer to here.
Translated by ChatGPT 5