CF1284B.New Year and Ascent Sequence

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A sequence a=[a1,a2,…,al]a = [a_1, a_2, \ldots, a_l] of length ll has an ascent if there exists a pair of indices (i,j)(i, j) such that 1≤i<j≤l1 \le i \lt j \le l and ai<aja_i \lt a_j. For example, the sequence [0,2,0,2,0][0, 2, 0, 2, 0] has an ascent because of the pair (1,4)(1, 4), but the sequence [4,3,3,3,1][4, 3, 3, 3, 1] doesn't have an ascent.

Let's call a concatenation of sequences pp and qq the sequence that is obtained by writing down sequences pp and qq one right after another without changing the order. For example, the concatenation of the [0,2,0,2,0][0, 2, 0, 2, 0] and [4,3,3,3,1][4, 3, 3, 3, 1] is the sequence [0,2,0,2,0,4,3,3,3,1][0, 2, 0, 2, 0, 4, 3, 3, 3, 1]. The concatenation of sequences pp and qq is denoted as p+qp+q.

Gyeonggeun thinks that sequences with ascents bring luck. Therefore, he wants to make many such sequences for the new year. Gyeonggeun has nn sequences s1,s2,…,sns_1, s_2, \ldots, s_n which may have different lengths.

Gyeonggeun will consider all n2n^2 pairs of sequences sxs_x and sys_y (1≤x,y≤n1 \le x, y \le n), and will check if its concatenation sx+sys_x + s_y has an ascent. Note that he may select the same sequence twice, and the order of selection matters.

Please count the number of pairs (x,yx, y) of sequences s1,s2,…,sns_1, s_2, \ldots, s_n whose concatenation sx+sys_x + s_y contains an ascent.

长度为 ll 的序列 a=[a1,a2,…,al]a = [a_1, a_2, \ldots, a_l] 若存在一对下标 (i,j)(i, j) 满足 1≤i<j≤l1 \le i \lt j \le l 且 ai<aja_i \lt a_j,则称该序列具有上升段(ascent)。例如,序列 [0,2,0,2,0][0, 2, 0, 2, 0] 具有上升段,因为存在下标对 (1,4)(1, 4);而序列 [4,3,3,3,1][4, 3, 3, 3, 1] 则不具有上升段。

我们把序列 pp 和 qq 的**拼接(concatenation)**定义为将 pp 和 qq 按原有顺序依次写在一起所得到的序列。例如,序列 [0,2,0,2,0][0, 2, 0, 2, 0] 与 [4,3,3,3,1][4, 3, 3, 3, 1] 的拼接结果为 [0,2,0,2,0,4,3,3,3,1][0, 2, 0, 2, 0, 4, 3, 3, 3, 1]。序列 pp 与 qq 的拼接记作 p+qp+q。

京根认为具有上升段的序列会带来好运。因此,他希望在新年到来之际构造尽可能多的此类序列。京根手头有 nn 个序列 s1,s2,…,sns_1, s_2, \ldots, s_n,它们的长度可能各不相同。

京根将考察所有 n2n^2 对序列 (sx,sy)(s_x, s_y)(其中 1≤x,y≤n1 \le x, y \le n),并检查其拼接序列 sx+sys_x + s_y 是否具有上升段。注意:他允许选择同一个序列两次,且顺序是有区别的(即 (x,y)(x,y) 与 (y,x)(y,x) 被视为不同对)。

请统计满足条件的序列对 (x,y)(x, y) 的数量,即拼接序列 sx+sys_x + s_y 中包含上升段的对数。

输入格式

The first line contains the number nn (1≤n≤100 0001 \le n \le 100\,000) denoting the number of sequences.

The next nn lines contain the number lil_i (1≤li1 \le l_i) denoting the length of sis_i, followed by lil_i integers si,1,si,2,…,si,lis_{i, 1}, s_{i, 2}, \ldots, s_{i, l_i} (0≤si,j≤1060 \le s_{i, j} \le 10^6) denoting the sequence sis_i.

It is guaranteed that the sum of all lil_i does not exceed 100 000100\,000.

第一行包含一个整数 nn(1≤n≤100 0001 \le n \le 100\,000),表示序列的个数。

接下来的 nn 行中,每行首先给出一个整数 lil_i(1≤li1 \le l_i),表示序列 sis_i 的长度,随后是 lil_i 个整数 si,1,si,2,…,si,lis_{i, 1}, s_{i, 2}, \ldots, s_{i, l_i}(0≤si,j≤1060 \le s_{i, j} \le 10^6),表示序列 sis_i。

保证所有 lil_i 的总和不超过 100 000100\,000。

输出格式

Print a single integer, the number of pairs of sequences whose concatenation has an ascent.

输出一个整数,表示满足其连接序列具有上升段的序列对的数量。

输入输出样例

  • 输入#1

    5
    1 1
    1 1
    1 2
    1 4
    1 3

    输出#1

    9
  • 输入#2

    3
    4 2 0 2 0
    6 9 9 8 8 7 7
    1 6

    输出#2

    7
  • 输入#3

    10
    3 62 24 39
    1 17
    1 99
    1 60
    1 64
    1 30
    2 79 29
    2 20 73
    2 85 37
    1 100

    输出#3

    72

说明/提示

For the first example, the following 99 arrays have an ascent: [1,2],[1,2],[1,3],[1,3],[1,4],[1,4],[2,3],[2,4],[3,4][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.

对于第一个样例,以下 99 个数组具有上升段(ascent):[1,2],[1,2],[1,3],[1,3],[1,4],[1,4],[2,3],[2,4],[3,4][1, 2], [1, 2], [1, 3], [1, 3], [1, 4], [1, 4], [2, 3], [2, 4], [3, 4]。内容相同的数组按其出现次数分别计数。

输入解题思路,AI测评打分。不知道怎么写?

首页