luogu#P7972. [KSN2021] Self Permutation
[KSN2021] Self Permutation
Problem Description
Given a permutation of length , you may perform the following operation any number of times:
- Choose two adjacent numbers and delete the larger one of them.
Ask for the number of different sequences that can be obtained in the end. Output the answer modulo .
Note that if all numbers between two numbers are deleted, then they will become adjacent.
Input Format
The first line contains a positive integer .
The second line contains positive integers .
Output Format
Output one integer representing the answer.
3
2 3 1
3
4
2 1 4 3
6
Hint
Sample Explanation
For the first sample, the following are all possible sequences that can be obtained:
For the second sample, the following are all possible sequences that can be obtained:
- $[\bold2,\bold1, 4, 3]\to[1,\bold4,\bold3]\to[\bold1,\bold3]\to[1]$
Constraints
This problem uses bundled testdata.
- Subtask 1 (8 points): There is only one test case, with , .
- Subtask 2 (20 points): .
- Subtask 3 (13 points): , .
- Subtask 4 (9 points): .
- Subtask 5 (23 points): .
- Subtask 6 (27 points): No special restrictions.
For all testdata, , and it is guaranteed that the input forms a permutation.
Translated by ChatGPT 5