| 2025 GUC Winter Camp |
|---|
| Закончено |
Professor Hussein is a renowned researcher in digital signal processing. He models complex, repeating signals as permutations. A permutation of length $$$n$$$ is an arrangement of the integers from $$$1$$$ to $$$n$$$, inclusive, where each integer appears exactly once.
For example, $$$[2, 1, 4, 3]$$$ and $$$[1, 2]$$$ are permutations, while $$$[1, 3, 1]$$$ and $$$[1, 2, 4]$$$ are not.
A key operation in the professor's analysis is the cyclical left rotation. Given a permutation $$$p$$$, we define $$$\mathrm{rot}(p)$$$ as the permutation obtained by shifting $$$p$$$ one position to the left, with the first element wrapping around to the end.
For example, if $$$p = [1, 3, 4, 2]$$$, then $$$\mathrm{rot}(p) = [3, 4, 2, 1]$$$.
More generally, $$$\mathrm{rot}^i(p)$$$ is the result of applying the left rotation operation $$$i$$$ times. For instance, $$$\mathrm{rot}^2(p) = [4, 2, 1, 3]$$$.
Professor Hussein is particularly interested in a property he calls stable indices. An index $$$i$$$ (where $$$1 \le i \le n$$$) is a stable index of a permutation $$$p$$$ if applying the permutation mapping twice, starting from that index, returns the original index. Formally, $$$i$$$ is a stable index if: $$$$$$p[p[i]] = i$$$$$$
We denote $$$S(p)$$$ as the total number of stable indices in the permutation $$$p$$$.
Example:
Let $$$p = [3, 6, 1, 4, 2, 5]$$$.
Thus, $$$S(p) = 3$$$.
Given a permutation $$$p$$$ of length $$$n$$$ and a total number of rotations $$$k$$$, you must calculate the sum of the stable index counts for the first $$$k$$$ rotations (starting from the 0-th rotation, which is $$$p$$$ itself).
Your goal is to compute: $$$$$$\sum_{i=0}^{k-1} S(\mathrm{rot}^i(p))$$$$$$
Since $$$k$$$ can be extremely large, a simple simulation of each rotation is not feasible.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le 10^9$$$) — the length of the permutation and the total number of rotations to sum over.
The second line contains $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the elements of the initial permutation $$$p$$$.
Print a single integer representing the calculated Total Stability Score.
6 33 6 1 4 2 5
6
4 51 2 3 4
12
| Название |
|---|


