[Solution] Doping Codeforces Solution
We call an array of length fancy if for each it holds that .
Let's call applied to a permutation of length as the minimum number of subarrays it can be partitioned such that each one of them is fancy. For example , while and .
Given and a permutation of length , we define a permutation of length to be -special if and only if:
- is lexicographically smaller than , and
- .
Your task is to count for each the number of -special permutations modulo .
A permutation is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array) and is also not a permutation ( but there is in the array).
A permutation of length is lexicographically smaller than a permutation of length if and only if the following holds: in the first position where and differ, the permutation has a smaller element than the corresponding element in .
The first line contains two integers and (, ) — the length of the permutation and the required modulo.
The second line contains distinct integers () — the permutation .
Print integers, where the -th integer is the number of -special permutations modulo .
In the first example, the permutations that are lexicographically smaller than are:
- , ;
- , ;
- , .
Thus our answer is .
In the second example, the permutations that are lexicographically smaller than are:
- , ;
- , ;
- , ;
- , ;
- , .
Thus our answer is .
No comments:
Post a Comment