CF1284B New Year and Ascent Sequence

题目描述

### 题意简述 给定 $n$ 个整数序列 $s_1,s_2,...,s_n$。 我们可以把两个长分别为 $lx$ 和 $ly$ 的序列 $s_a,s_b$ 拼接起来,拼接后的序列是 $[s_{a,1},s_{a,2},...,s_{a,lx},s_{b,1},s_{b,2},...,s_{b,ly}]$。 容易发现,如果在 $n$ 个序列中任选两个拼起来,一共有 $n^2$ 种拼法。 现在问你在 $n^2$ 种拼法拼成的序列中有多少个拼成的长度为 $l$ 的序列 $a$,使得存在 $(i,j)$ 满足 $1\leq i

输入格式

第一行一个正整数 $n(1\leq n \leq 10^5)$。 接下来 $n$ 行,每行的第一个正整数 $l_i(1\leq l_i)$ 表示第 $i$ 个序列的长度。接下来 $l_i$ 个整数 $s_{i,1},s_{i,2},...,s_{i,l_i}(1\leq s_i \leq 10^6)$。 $\sum l_i$ 不会超过 $10^5$。

输出格式

输出一行,表示满足条件的序列数量。

说明/提示

For the first example, the following $ 9 $ arrays have an ascent: $ [1, 2], [1, 2], [1, 3], [1, 3], [1, 4], [1, 4], [2, 3], [2, 4], [3, 4] $ . Arrays with the same contents are counted as their occurences.