CF2185G.Mixing MEXes
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n arrays a1,a2,…,an.
The following operation is performed exactly once:
- Choose any array among a1,a2,…,an. Suppose you've chosen array ai (1≤i≤n).
- Choose any element in array ai. Suppose you've chosen the j-th element of ai, denoted by ai,j (1≤j≤∣ai∣, where ∣ai∣ denotes the length of array ai).
- Choose any other array among a1,a2,…an that is not ai. Suppose you've chosen ak (1≤k≤n,k=i).
- Add ai,j to the back of array ak. Then, remove ai,j from ai.
- The value of this operation (i,j,k) is defined as the sum of each array's MEX after the operation is performed. More formally, the value of an operation after the operation is performed is ∑i=1nMEX(ai).
Evaluate the sum of the values of all possible distinct independent operations. Two operations are distinct if the ordered triple of integers (i,j,k) is different.
MEX(a) is defined as the smallest non-negative integer that is not present in the array. For example, MEX([1,2,0,5]) is 3, and MEX([1,2,4,9]) is 0.
给你 n 个数组 a1,a2,…,an。
以下操作恰好执行一次:
- 在 a1,a2,…,an 中任选一个数组。假设你选择了数组 ai(其中 1≤i≤n)。
- 在数组 ai 中任选一个元素。假设你选择了 ai 的第 j 个元素,记为 ai,j(其中 1≤j≤∣ai∣,∣ai∣ 表示数组 ai 的长度)。
- 在 a1,a2,…,an 中另选一个不同于 ai 的数组。假设你选择了 ak(其中 1≤k≤n 且 k=i)。
- 将 ai,j 添加到数组 ak 的末尾;然后从 ai 中删除 ai,j。
- 此操作 (i,j,k) 的值定义为:操作执行后,所有数组的 MEX 值之和。更准确地说,该操作的值为 ∑i=1nMEX(ai)。
请计算所有可能的、互不相同的独立操作的值之和。若两个操作对应的三元组 (i,j,k)(有序整数三元组)不同,则称这两个操作互不相同。
MEX(a) 定义为数组 a 中未出现的最小非负整数。例如,MEX([1,2,0,5])=3,而 MEX([1,2,4,9])=0。
输入格式
The first line of the input contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains a single integer n (2≤n≤2⋅105) — the number of arrays.
The next n lines start with li (1≤li≤105) — the length of the ith array — then contain li integers a1,a2,…,ali (0≤aij≤106) — the array ai.
It is guaranteed that the sum of li over all test cases does not exceed 2⋅105.
输入的第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
每个测试用例的第一行包含一个整数 n(2≤n≤2⋅105)—— 表示数组的个数。
接下来的 n 行,每行以 li(1≤li≤105)开头,表示第 i 个数组的长度;随后是 li 个整数 a1,a2,…,ali(0≤aij≤106)—— 即数组 ai。
保证所有测试用例中 li 的总和不超过 2⋅105。
输出格式
For each test case, output the sum of the values of all possible distinct operations.
对于每个测试用例,输出所有可能的不同操作的值的总和。
输入输出样例
输入#1
6 2 1 0 2 1 2 3 1 1 2 2 3 3 4 5 6 5 4 1 7 8 10 2 5 6 2 0 7 2 6 6 2 6 8 2 1 3 3 0 1 2 2 6 0 0 1 2 2 3 3 0 2 3 10 1 0 9 7 8 0 1 5 6 4 3 2 8 4 3 8 6 2 5 0 1 7 2 3 0 1 0 4 0 2 3 1 9 2 0 5 4 1 3 0 0 0 7 6 3 2 4 1 8 0 5 3 2 4 1 0 4 0 3 1 1 3 0 3 2
输出#1
6 0 50 8 43 19202
说明/提示
For the first test case, we have 3 possible distinct operations:
- i=1,j=1,k=2: The arrays are now [] and [0,1,2], which have a mex of 0 and 3 respectively, so the value of the operation is 3.
- i=2,j=1,k=1: The arrays are now [0,1] and [2], which have a mex of 2 and 0 respectively, so the value of the operation is 2.
- i=2,j=2,k=1: The arrays are now [0,2] and [1], which have a mex of 1 and 0 respectively, so the value of the operation is 1.
For the second test case, since no array contains a zero, the value of all operations will be 0.
对于第一个测试用例,我们有 3 种可能的互不相同的操作:
- i=1,j=1,k=2:此时两个数组分别为 [] 和 [0,1,2],它们的 mex 值分别为 0 和 3,因此该操作的值为 3。
- i=2,j=1,k=1:此时两个数组分别为 [0,1] 和 [2],它们的 mex 值分别为 2 和 0,因此该操作的值为 2。
- i=2,j=2,k=1:此时两个数组分别为 [0,2] 和 [1],它们的 mex 值分别为 1 和 0,因此该操作的值为 1。
对于第二个测试用例,由于没有任何数组包含 0,所有操作的值均为 0。
输入解题思路,AI测评打分。不知道怎么写?