QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 512 MB Puntuación total: 100 Hackeable ✓

#7311. 欢迎来到 ICPCCamp 2017

Estadísticas

ICPCCamp 队伍通常通过博客(?)中描述的一种神秘的 $(X, Y)$-规则来选拔。

共有 $(n+1)$ 场选拔赛,用于从 $m$ 支队伍(编号为 $1, 2, \dots, m$)中选出 ICPCCamp 队伍。第 $i$ 场比赛的参赛队伍数量为 $k_i$。由于最后一场(第 $(n+1)$ 场)比赛被称为 EasyCamp-Final,非常重要,因此始终满足 $k_{n+1} = m$。第 $i$ 场比赛的记分牌为 $r_{i,1}, r_{i,2}, \dots, r_{i,k_i}$,表示队伍 $r_{i,j}$ 在该场比赛中排名第 $j$。

$(X, Y)$-规则的工作方式如下:首先,选择两个非负整数 $X$ 和 $Y$,以及 $\{1, 2, \dots, n\}$ 的一个排列 $P = \{p_1, p_2, \dots, p_n\}$。之后,列表 $\{r_{n+1,1}, r_{n+1,2}, \dots, r_{n+1,Y}, r_{p_1,1}, r_{p_2,1}, \dots, r_{p_n,1}, r_{p_1,2}, r_{p_2,2}, \dots, r_{p_n,2}, \dots \}$ 中的前 $X+Y$ 个不同的队伍将被选为 ICPCCamp 队伍。换句话说,列表的顺序如下:首先是 EasyCamp-Final 的前 $Y$ 支队伍,然后是按照 $P$ 定义的顺序排列的前 $n$ 场比赛的第一名,接着是按照相同顺序排列的前 $n$ 场比赛的第二名,以此类推。

Bobo 想知道,如果他可以任意选择 $X$、$Y$ 和 $P$,那么可能的 ICPCCamp 队伍集合有多少种?请输出结果对 $(10^9 + 7)$ 取模后的值。

输入格式

输入包含零个或多个测试用例,并以文件结束符(EOF)终止。对于每个测试用例:

第一行包含两个整数 $n$ 和 $m$ ($0 \le n \le 2 \cdot 10^5$, $1 \le m \le 2 \cdot 10^5$)。

接下来的 $n$ 行,第 $i$ 行包含一个整数 $k_i$,随后是 $k_i$ 个整数 $r_{i,1}, r_{i,2}, \dots, r_{i,k_i}$ ($1 \le k_i \le m$)。

最后一行包含 $m$ 个整数 $r_{n+1,1}, r_{n+1,2}, \dots, r_{n+1,m}$ ($1 \le r_{i,j} \le m$,且对于每个 $i$,集合 $\{r_{i,1}, r_{i,2}, \dots, r_{i,k_i}\}$ 中的数字互不相同)。

保证所有 $k_i$ 之和与所有 $m$ 之和均不超过 $2 \cdot 10^5$。

输出格式

对于每个测试用例,输出一个整数,表示可能的集合数量对 $(10^9 + 7)$ 取模的结果。

样例

输入 1

2 3
2 1 3
3 2 1 3
2 1 3
0 3
1 2 3

输出 1

5
4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.