#P8145. [JRKSJ R4] kth

    ID: 9073 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2022洛谷原创动态规划优化

[JRKSJ R4] kth

Background

Always remember that you are a human, not an animal.

Before eating corn-and-tomato stewed goat meat, you need to answer a question.

Problem Description

Given n,mn, m, call an integer sequence “valid” (denote it by ss) if:

  • The length of ss is mm.
  • i[1,m],si[1,n]\forall i\in[1,m], s_i\in[1,n].
  • i[2,m],sisi1=1\forall i\in[2,m], |s_i-s_{i-1}|=1.

Given a permutation pp of [1,n][1,n], define the “corresponding sequence” ss' of an integer sequence ss as follows: ss' has the same length as ss. Let the length be ll. Then i[1,l],si=psi\forall i\in [1,l], s'_i=p_{s_i}.

Given kk, among the corresponding sequences of all distinct valid integer sequences, find the sum of all elements of the kk-th smallest corresponding sequence in lexicographical order, modulo 2322^{32}.

If the kk-th smallest corresponding sequence does not exist, output 1-1.

Input Format

The first line contains three integers n,m,kn, m, k.
The second line contains nn integers representing pp.

Output Format

Output one integer, representing the answer.

10 6 3
5 7 4 3 6 2 10 8 9 1
38
2 5 2
1 2
8
2 114514 1
2 1
171771
3 1000000000000000000 3
2 1 3
2065039361

Hint

The input file of this problem is large, so please use an appropriate input method.

Sample Explanation

For sample 11, among the corresponding sequences of all distinct valid integer sequences, the three smallest in lexicographical order are:

{1,9,1,9,1,9}\{1,9,1,9,1,9\} {1,9,1,9,8,9}\{1,9,1,9,8,9\} {1,9,1,9,8,10}\{1,9,1,9,8,10\}

So the answer is 1+9+1+9+8+10=381+9+1+9+8+10=38.

For sample 22, among the corresponding sequences of all distinct valid integer sequences, the two smallest in lexicographical order are:

{1,2,1,2,1}\{1,2,1,2,1\} {2,1,2,1,2}\{2,1,2,1,2\}

So the answer is 2+1+2+1+2=82+1+2+1+2=8.

Constraints

Subtask\text{Subtask} nn\le mm\le kk\le Score
11 2020 1010 101810^{18} 55
22 7070 1515
33 100100 300300 2020
44 10410^4 10410^4 1515
55 101810^{18} 1010
66 10610^6 11 55
77 2×1072\times10^7 101810^{18} 3030

For 100%100\% of the data, 1n2×1071\le n\le 2\times10^7, 2m10182\le m\le 10^{18}, 1k10181\le k\le 10^{18}.

Special Scoring Method

This problem uses subtask dependencies, as follows:

  • For subtasks i{1,6}i\in\{1,6\}, you only need to solve subtask ii correctly to get the score of subtask ii.
  • For subtasks i{2,3,4,5,7}i\in\{2,3,4,5,7\}, you need to solve all subtasks j[1,i]j\in[1,i] correctly to get the score of subtask ii.

Translated by ChatGPT 5