#P4485. [BJWC2018] 拓扑序列
[BJWC2018] 拓扑序列
Description
Xiao C recently learned about topological sorting. Performing a topological sort on a directed acyclic graph means arranging all vertices of into a linear order such that for any directed edge in , appears before in the linear order. For example, if the vertex set of is and the edge set is , then and are both topological sequences of .
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 edges, and that there exists a vertex 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 .
Input Format
The first line contains three integers .
The second line contains space-separated positive integers , representing a topological sequence of the original graph, guaranteed to be a permutation of to .
Output Format
Output a single integer, the remainder modulo 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 simple directed acyclic graphs that satisfy the requirements. Their edge sets are:
Constraints
For of the testdata, , .

Translated by ChatGPT 5
京公网安备 11011102002149号