#P4485. [BJWC2018] 拓扑序列

[BJWC2018] 拓扑序列

Description

Xiao C recently learned about topological sorting. Performing a topological sort on a directed acyclic graph GG means arranging all vertices of GG into a linear order such that for any directed edge (u,v)(u, v) in GG, uu appears before vv in the linear order. For example, if the vertex set of GG is {1,2,3,4}\{1,2,3,4\} and the edge set is {(1,2),(1,3),(2,4),(3,4)}\{(1,2) ,(1,3),(2,4),(3,4)\}, then (1,2,3,4)(1,2,3,4) and (1,3,2,4)(1,3,2,4) are both topological sequences of GG.

Now Xiao C performed a topological sort on a simple (no multiple edges) directed acyclic graph, but accidentally lost the original graph. Besides the topological sequence, he only remembers that the original graph has kk edges, and that there exists a vertex uu that can reach all other vertices in the graph. He wants to know how many simple directed acyclic graphs satisfy the above requirements. Since the answer may be large, you only need to output the answer modulo mm.

Input Format

The first line contains three integers n,k,mn, k, m.

The second line contains nn space-separated positive integers a1,a2,,ana_1, a_2, \dots, a_n, representing a topological sequence of the original graph, guaranteed to be a permutation of 11 to nn.

Output Format

Output a single integer, the remainder modulo mm of the number of simple directed acyclic graphs that satisfy the requirements.

4 4 4
1 2 3 4
1

Hint

【Sample Explanation】

There are 99 simple directed acyclic graphs that satisfy the requirements. Their edge sets are:

{(1,2),(1,3),(1,4),(2,3)}\{(1, 2), (1, 3), (1, 4), (2, 3)\}

{(1,2),(1,3),(1,4),(2,4)}\{(1, 2), (1, 3), (1, 4), (2, 4)\}

{(1,2),(1,3),(1,4),(3,4)}\{(1, 2), (1, 3), (1, 4), (3, 4)\}

{(1,2),(1,3),(2,3),(2,4)}\{(1, 2), (1, 3), (2, 3), (2, 4)\}

{(1,2),(1,3),(2,3),(3,4)}\{(1, 2), (1, 3), (2, 3), (3, 4)\}

{(1,2),(1,3),(2,4),(3,4)}\{(1, 2), (1, 3), (2, 4), (3, 4)\}

{(1,2),(1,4),(2,3),(2,4)}\{(1, 2), (1, 4), (2, 3), (2, 4)\}

{(1,2),(1,4),(2,3),(3,4)}\{(1, 2), (1, 4), (2, 3), (3, 4)\}

{(1,2),(2,3),(2,4),(3,4)}\{(1, 2), (2, 3), (2, 4), (3, 4)\}

Constraints

For 100%100\% of the testdata, 0kn2×1050 \le k \le n \le 2 \times 10^5, 1m102000001 \le m \le 10^{200000}.

Translated by ChatGPT 5