#P11748. 「TPOI-1B」ASPAP
「TPOI-1B」ASPAP
Description
You have permutations of length sorted in lexicographical order.
Among the first permutations in this order, find a permutation that maximizes . Output this maximum value modulo .
Input Format
The first line contains an integer .
Each of the next lines contains two integers and .
Output Format
For each query, output one integer representing the maximum value modulo .
1
4 5
23
Hint
Explanation for Sample #1
The first five permutations of length are:
- $1, 2, 3, 4 \to 1 + (1+2) + (1+2+3) + (1+2+3+4) = 20$
- $1, 2, 4, 3 \to 1 + (1+2) + (1+2+4) + (1+2+4+3) = 21$
- $1, 3, 2, 4 \to 1 + (1+3) + (1+3+2) + (1+3+2+4) = 21$
- $1, 3, 4, 2 \to 1 + (1+3) + (1+3+4) + (1+3+4+2) = 23$
- $1, 4, 2, 3 \to 1 + (1+4) + (1+4+2) + (1+4+2+3) = 23$
The maximum value is .
Constraints
This problem uses bundled tests. You must pass all test cases in a subtask to receive points.
| Subtask | Points | Special Constraints |
|---|---|---|
| 1 | 10 | |
| 2 | , | |
| 3 | 25 | |
| 4 | 5 | |
| 5 | 50 | No special constraints |
For data: , , .
Translated by DeepSeek R1
京公网安备 11011102002149号