#P15064. [UOI 2024 II Stage] Everyone Loves Permutations
[UOI 2024 II Stage] Everyone Loves Permutations
题目描述
A permutation of length is an array of length containing all integers from to , and all its elements are pairwise distinct.
Having grown up and played with arrays, Anton moved on to studying more interesting arrays --- permutations. While writing his thesis, he faced a very difficult task.
He has a permutation of length and an integer . He decided to construct a two-dimensional array with sizes .
- for all ();
- for all () and ().
Let and , then we have the following array.
$$\begin{array}{|c|c|c|c|c|c|} \hline a_{ij} & j=1 & j=2 & j=3 & j=4 & j=5 \\ \hline\hline i=0 & 1 & 2 & 3 & 4 & 5 \\ \hline i=1 & 5 & 3 & 1 & 4 & 2 \\ \hline i=2 & 2 & 1 & 5 & 4 & 3 \\ \hline i=3 & 3 & 5 & 2 & 4 & 1 \\ \hline \end{array}$$For each (), he wants to know the sum of all such that , where . In other words, he wants to find the sum of numbers --- the indices of the number in each .
Consider the last example. If , the answer will be .
After some deliberation and simple ideas, Anton managed to solve this problem quickly. Now he wants to check if you can solve it too.
输入格式
The first line of the input contains two integers , (, ) --- the length of the permutation and the number of repetitions of operations, respectively.
The second line contains the permutation ().
输出格式
Print integers, where the -th number is the answer for .
3 2
2 1 3
3 3 6
5 3
5 3 1 4 2
10 9 8 12 6
提示
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): , for any and , there exists a such that , where the nesting is taken times;
- ( points): for any and , there exists a such that , where the nesting is taken times;
- ( points): without additional restrictions.