#P10813. 【MX-S2-T4】 换
【MX-S2-T4】 换
Background
Original link: https://oier.team/problems/S2D。
Problem Description
Given and a sequence of length : .
Find how many positive integer sequences of length satisfy that every element meets , and after performing the following operation in order for , the sequence becomes non-decreasing:
- If , swap the values of and .
Output the answer modulo .
Input Format
The first line contains three integers .
The next lines each contain two integers .
Output Format
Output one integer, the result modulo .
3 3 5
3 2
1 3
1 2
2 3
2 1
12
8 900000754 20
5 5
1 2
3 2
1 8
4 8
5 8
3 4
3 7
5 7
3 4
6 8
1 5
7 8
7 8
5 7
1 8
3 8
3 8
5 6
3 8
508510094
Hint
Sample Explanation #1
For the first sample, there are valid sequences:
, , , , , , , , , , , 。
Constraints
This problem uses bundled testdata.
- Subtask 0 (8 pts): , , .
- Subtask 1 (31 pts): .
- Subtask 2 (37 pts): .
- Subtask 3 (24 pts): no special constraints.
For all testdata, , , , . Note that the relative order of and is not guaranteed, and the data may contain .
Translated by ChatGPT 5