

Time Limit: 3 sec / Memory Limit: 1024 MB
配点 : 点
問題文
長さ の整数列 があります。 すべての要素ははじめ です。
整数 と 個の区間 が与えられます。
あなたは、 の順列 と長さ の整数列 を選びます。 ここで、 でなければなりません。
そして、 回の変更を行います。 回目の変更は以下です。
- を に変える。
の中のすべての位置が少なくとも一つの区間に覆われることが保証されます。
すべての変更後の としてありうるものの個数を求め、答えを で割った余りを出力してください。
制約
- ()
- の中のすべての位置は少なくとも一つの区間に覆われる。
- すべての入力値は整数である。
入力
入力は標準入力から以下の形式で与えられる。
出力
答えを出力せよ。
入力例 1Copy
5 5 2 1 3 2 2 3 3 1 5 3 5
出力例 1Copy
16
ありうる数列は 個あります。 例えば、 は以下のようにして得られます。
- と を選ぶ
- 回目の操作で が になる
- 回目の操作で が になる
- 回目の操作で が になる
- 回目の操作で が になる
- 回目の操作で が になる
入力例 2Copy
20 30 20 1 14 1 7 1 16 3 13 1 17 4 8 2 11 4 12 9 14 3 15 11 19 1 13 4 15 8 19 3 17 15 18 10 18 1 18 17 19 16 20 1 8 8 15 13 17 1 19 13 19 1 20 6 13 10 12 11 20 17 18
出力例 2Copy
258066445
Score : points
Problem Statement
You have an integer sequence of length . All elements are initially .
You are given an integer and intervals .
You will choose a permutation of and an integer sequence of length . Here, must hold.
Then, you will do modifications. The -th modification is the following:
- Change to .
It is guaranteed that every position in is covered by at least one interval.
Find the number of achievable after all modifications. Print the answer modulo .
Constraints
- ()
- Every position in is covered by at least one interval.
- All input values are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1Copy
5 5 2 1 3 2 2 3 3 1 5 3 5
Sample Output 1Copy
16
There are sequences that can be achieved. For example, you can achieve in the following manner:
- Choose and
- The -st operation changes into
- The -nd operation changes into
- The -rd operation changes into
- The -th operation changes into
- The -th operation changes into
Sample Input 2Copy
20 30 20 1 14 1 7 1 16 3 13 1 17 4 8 2 11 4 12 9 14 3 15 11 19 1 13 4 15 8 19 3 17 15 18 10 18 1 18 17 19 16 20 1 8 8 15 13 17 1 19 13 19 1 20 6 13 10 12 11 20 17 18
Sample Output 2Copy
258066445