#abc313h. Ex - Group Photo
Ex - Group Photo
Score : points
问题陈述
设有 名人员排成两排拍摄团体照。前排有 名人员,其中第 个的身高为 ;后排有 名人员,其中第 个的身高为 。保证这 名人员的身高各不相同。在每一排内,我们可以自由调整人员顺序。
假设从前到后,前排人员的身高依次为 ,后排人员的身高依次为 。若满足以下所有条件,则称这种排列方式为好的排列:
- 对于所有 ,满足 或 。
- 满足 。
- 满足 。
在前排 种排列方式中,有多少种(模 )可以通过重新排列后排人员使得排列变为好的排列方式?
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
people are forming two rows to take a group photograph. There are people in the front row; the -th of them has a height of . There are people in the back row; the -th of them has a height of . It is guaranteed that the heights of the people are distinct. Within each row, we can freely rearrange the people.
Suppose that the heights of the people in the front row are from the left, and those in the back row are from the left. This arrangement is said to be good if all of the following conditions are satisfied:
- or for all .
- .
- .
Among the ways to rearrange the front row, how many of them, modulo , are such ways that we can rearrange the back row to make the arrangement good?
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
3
1 12 6
4 3 10 9
Sample Output 1
2
- When , we can let, for example, to make the arrangement good.
- When , we can let, for example, to make the arrangement good.
- When is one of the other four ways, no rearrangement of the back row (that is, none of the possible candidates of ) makes the arrangement good.
Thus, the answer is .
Sample Input 2
1
5
1 10
Sample Output 2
0
Sample Input 3
10
189330739 910286918 802329211 923078537 492686568 404539679 822804784 303238506 650287940 1
125660016 430302156 982631932 773361868 161735902 731963982 317063340 880895728 1000000000 707723857 450968417
Sample Output 3
3542400
update @ 2024/3/10 08:57:03