| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 512 MB | 86 | 37 | 26 | 37.143% |
Given a permutation $A = (a_1, a_2, \dots, a_N)$ of the integers 1,ドル 2, \dots, N,ドル we define the greedily increasing subsequence (GIS) in the following way.
Let $g_1 = a_1$. For every $i > 1,ドル let $g_i$ be the leftmost integer in $A$ that is strictly larger than $g_{i-1}$. If for a given $i$ there is no such integer, we say that the GIS of the sequence is the sequence $(g_1, g_2, ..., g_{i - 1})$.
For example, consider the permutation $(2, 3, 1, 5, 4, 7, 6)$. First, we have $g_1 = 2$. The leftmost integer larger than 2ドル$ is 3ドル,ドル so $g_2 = 3$. The leftmost integer larger than 3ドル$ is 5ドル$ (1ドル$ is too small), so $g_3 = 5$. Finally, $g_4 = 7$. Thus, the GIS of $(2, 3, 1, 5, 4, 7, 6)$ is $(2, 3, 5, 7)$.
Given a sequence $G = (g_1, g_2, \dots, g_L),ドル how many permutations $A$ of the integers 1,ドル 2, \dots, N$ have $G$ as its GIS?
The first line of input contains the integers 1ドル \le N \le 10^6,ドル the number of elements of the permutation $A,ドル and 1ドル \le L \le 10^6,ドル the length of the sequence $G$.
The next line contains $L$ positive integers between 1ドル$ and $N,ドル the elements $g_1, \dots, g_L$ of the sequence $G$.
Output a single integer: the number of $N$-element permutations having the given sequence as its GIS. Since this number may be large, output it modulo the prime number 10ドル^9 + 7$.
5 1 1
0
5 1 5
24
5 3 2 4 5
8
7 4 1 4 5 7
20