#P3205. [HNOI2010] 合唱队
[HNOI2010] 合唱队
Description
To achieve a better performance at the upcoming gala, Xiao A, the leader of the AAA choir, needs to arrange the choir members into a lineup based on their heights. Suppose there are people in total, the -th person’s height is meters (), and any two people have different heights. Suppose the final lineup consists of people standing in one row. To simplify the process, Xiao A came up with the following method: he first lets everyone stand in an initial lineup in an arbitrary order, and then, from left to right, inserts each person into the final lineup according to these rules:
-
The first person is directly inserted into the empty current lineup.
-
For each person starting from the second, if he is taller than the person immediately before him in the initial lineup ( is larger), insert him at the right end of the current lineup. If he is shorter ( is smaller), insert him at the left end.
After all people have been inserted into the current lineup, the final lineup is obtained.
For example, there are people in the initial lineup, with heights .
Then Xiao A will obtain the final lineup step by step as follows:
-
-
1850, 1900, because .
-
1700, 1850, 1900, because .
-
1650, 1700, 1850, 1900, because .
-
1650, 1700, 1850, 1900, 1800, because .
-
1750, 1650, 1700, 1850, 1900, 1800, because .
Therefore, the final lineup is 1750, 1650, 1700, 1850, 1900, 1800.
Xiao A has an ideal lineup in mind and wants to know how many initial lineups can result in that ideal lineup.
Compute the answer modulo .
Input Format
The first line contains an integer .
The second line contains integers, representing Xiao A’s ideal lineup.
Output Format
Output one line with a single integer, which is the value of the answer .
4
1701 1702 1703 1704
8
Hint
For 30% of the testdata, .
For 100% of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号