Codeforces Round 968 (Div. 2) |
---|
Finished |
The two versions are different problems. In this version of the problem, you can choose the same integer twice or more. You can make hacks only if both versions are solved.
One day, Turtle was playing with $$$n$$$ sequences. Let the length of the $$$i$$$-th sequence be $$$l_i$$$. Then the $$$i$$$-th sequence was $$$a_{i, 1}, a_{i, 2}, \ldots, a_{i, l_i}$$$.
Piggy gave Turtle a problem to solve when Turtle was playing. The statement of the problem was:
Turtle solved the above problem without difficulty. He defined $$$f(k)$$$ as the answer to the above problem when the initial value of $$$x$$$ was $$$k$$$.
Then Piggy gave Turtle a non-negative integer $$$m$$$ and asked Turtle to find the value of $$$\sum\limits_{i = 0}^m f(i)$$$ (i.e., the value of $$$f(0) + f(1) + \ldots + f(m)$$$). Unfortunately, he couldn't solve this problem. Please help him!
$$$^{\dagger}\text{mex}(c_1, c_2, \ldots, c_k)$$$ is defined as the smallest non-negative integer $$$x$$$ which does not occur in the sequence $$$c$$$. For example, $$$\text{mex}(2, 2, 0, 3)$$$ is $$$1$$$, $$$\text{mex}(1, 2)$$$ is $$$0$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n, m$$$ ($$$1 \le n \le 2 \cdot 10^5, 0 \le m \le 10^9$$$).
Each of the following $$$n$$$ lines contains several integers. The first integer $$$l_i$$$ ($$$1 \le l_i \le 2 \cdot 10^5$$$) represents the length of the $$$i$$$-th sequence, and the following $$$l_i$$$ integers $$$a_{i, 1}, a_{i, 2}, \ldots, a_{i, l_i}$$$ ($$$0 \le a_{i, j} \le 10^9$$$) represent the elements of the $$$i$$$-th sequence.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$, and the sum of $$$\sum l_i$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single integer — the value of $$$\sum\limits_{i = 0}^m f(i)$$$.
63 42 0 23 2 3 34 7 0 1 53 45 0 2 0 4 111 15 1 3 0 3 32 502 1 22 1 21 17 1 2 4 1 4 9 54 1145142 2 25 7 3 6 0 33 0 1 15 0 9 2 1 55 19198101 22 324003 03 1416324 2 14607284 1312631 2 0 14151955 1223554 192248 2 1492515 725556
16 20 1281 6 6556785365 1842836177961
In the first test case, when $$$x$$$ is initially $$$2$$$, Turtle can choose $$$i = 3$$$ and set $$$x$$$ to $$$\text{mex}(x, a_{3, 1}, a_{3, 2}, a_{3, 3}, a_{3, 4}) = \text{mex}(2, 7, 0, 1, 5) = 3$$$. It can be proved that Turtle can't make the value of $$$x$$$ greater than $$$3$$$, so $$$f(2) = 3$$$.
It can be seen that $$$f(0) = 3$$$, $$$f(1) = 3$$$, $$$f(2) = 3$$$, $$$f(3) = 3$$$, and $$$f(4) = 4$$$. So $$$f(0) + f(1) + f(2) + f(3) + f(4) = 3 + 3 + 3 + 3 + 4 = 16$$$.
In the second test case, when $$$x$$$ is initially $$$1$$$, Turtle can choose $$$i = 3$$$ and set $$$x$$$ to $$$\text{mex}(x, a_{3, 1}, a_{3, 2}, a_{3, 3}, a_{3, 4}, a_{3, 5}) = \text{mex}(1, 1, 3, 0, 3, 3) = 2$$$, and choose $$$i = 3$$$ and set $$$x$$$ to $$$\text{mex}(x, a_{3, 1}, a_{3, 2}, a_{3, 3}, a_{3, 4}, a_{3, 5}) = \text{mex}(2, 1, 3, 0, 3, 3) = 4$$$. It can be proved that Turtle can't make the value of $$$x$$$ greater than $$$4$$$, so $$$f(1) = 4$$$.
It can be seen that $$$f(0) = 4$$$, $$$f(1) = 4$$$, $$$f(2) = 4$$$, $$$f(3) = 4$$$, and $$$f(4) = 4$$$. So $$$f(0) + f(1) + f(2) + f(3) + f(4) = 4 + 4 + 4 + 4 + 4 = 20$$$.
In the fourth test case, it can be seen that $$$f(0) = 3$$$ and $$$f(1) = 3$$$. So $$$f(0) + f(1) = 3 + 3 = 6$$$.
Name |
---|