CF1893C.Freedom of Choice

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Let's define the anti-beauty of a multiset b1,b2,…,blen{b_1, b_2, \ldots, b_{len}} as the number of occurrences of the number lenlen in the multiset.

You are given mm multisets, where the ii-th multiset contains nin_i distinct elements, specifically: ci,1c_{i, 1} copies of the number ai,1a_{i,1}, ci,2c_{i, 2} copies of the number ai,2,…,ci,nia_{i,2}, \ldots, c_{i, n_i} copies of the number ai,nia_{i, n_i}. It is guaranteed that ai,1<ai,2<…<ai,nia_{i, 1} \lt a_{i, 2} \lt \ldots \lt a_{i, n_i}. You are also given numbers l1,l2,…,lml_1, l_2, \ldots, l_m and r1,r2,…,rmr_1, r_2, \ldots, r_m such that 1≤li≤ri≤ci,1+…+ci,ni1 \le l_i \le r_i \le c_{i, 1} + \ldots + c_{i, n_i}.

Let's create a multiset XX, initially empty. Then, for each ii from 11 to mm, you must perform the following action exactly once:

  1. Choose some viv_i such that li≤vi≤ril_i \le v_i \le r_i
  2. Choose any viv_i numbers from the ii-th multiset and add them to the multiset XX.

You need to choose v1,…,vmv_1, \ldots, v_m and the added numbers in such a way that the resulting multiset XX has the minimum possible anti-beauty.

我们定义多重集 {b1,b2,…,blen}\{b_1, b_2, \ldots, b_{\text{len}}\} 的**反美感(anti-beauty)**为该多重集中元素 len\text{len} 出现的次数。

给定 mm 个多重集,其中第 ii 个多重集包含 nin_i 个互不相同的元素,具体为:数字 ai,1a_{i,1} 出现 ci,1c_{i,1} 次,数字 ai,2a_{i,2} 出现 ci,2c_{i,2} 次,……,数字 ai,nia_{i,n_i} 出现 ci,nic_{i,n_i} 次。保证 ai,1<ai,2<…<ai,nia_{i,1} < a_{i,2} < \ldots < a_{i,n_i}。同时给定数组 l1,l2,…,lml_1, l_2, \ldots, l_m 和 r1,r2,…,rmr_1, r_2, \ldots, r_m,满足 1≤li≤ri≤ci,1+…+ci,ni1 \le l_i \le r_i \le c_{i,1} + \ldots + c_{i,n_i}。

我们构造一个初始为空的多重集 XX。然后,对每个 ii 从 11 到 mm,必须且仅执行一次以下操作:

  1. 选择某个整数 viv_i,满足 li≤vi≤ril_i \le v_i \le r_i;
  2. 从第 ii 个多重集中任选 viv_i 个数,加入多重集 XX。

你需要恰当地选择 v1,…,vmv_1, \ldots, v_m 以及每次所选的具体数字,使得最终得到的多重集 XX 的反美感尽可能小。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer mm (1≤m≤1051 \le m \le 10^5) — the number of given multisets.

Then, for each ii from 11 to mm, a data block consisting of three lines is entered.

The first line of each block contains three integers ni,li,rin_i, l_i, r_i (1≤ni≤105,1≤li≤ri≤ci,1+…+ci,ni≤10171 \le n_i \le 10^5, 1 \le l_i \le r_i \le c_{i, 1} + \ldots + c_{i, n_i} \le 10^{17}) — the number of distinct numbers in the ii-th multiset and the limits on the number of elements to be added to XX from the ii-th multiset.

The second line of the block contains nin_i integers ai,1,…,ai,nia_{i, 1}, \ldots, a_{i, n_i} (1≤ai,1<…<ai,ni≤10171 \le a_{i, 1} \lt \ldots \lt a_{i, n_i} \le 10^{17}) — the distinct elements of the ii-th multiset.

The third line of the block contains nin_i integers ci,1,…,ci,nic_{i, 1}, \ldots, c_{i, n_i} (1≤ci,j≤10121 \le c_{i, j} \le 10^{12}) — the number of copies of the elements in the ii-th multiset.

It is guaranteed that the sum of the values of mm for all test cases does not exceed 10510^5, and also the sum of nin_i for all blocks of all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 mm(1≤m≤1051 \le m \le 10^5),表示给定的多重集数量。

接着,对每个 ii(从 11 到 mm),输入一个由三行组成的数据块。

每个数据块的第一行包含三个整数 ni,li,rin_i, l_i, r_i(1≤ni≤1051 \le n_i \le 10^5,1≤li≤ri≤ci,1+…+ci,ni≤10171 \le l_i \le r_i \le c_{i, 1} + \ldots + c_{i, n_i} \le 10^{17}),分别表示第 ii 个多重集中不同元素的个数,以及从该多重集中向集合 XX 添加元素个数的上下界。

每个数据块的第二行包含 nin_i 个整数 ai,1,…,ai,nia_{i, 1}, \ldots, a_{i, n_i}(1≤ai,1<…<ai,ni≤10171 \le a_{i, 1} \lt \ldots \lt a_{i, n_i} \le 10^{17}),表示第 ii 个多重集中的互异元素。

每个数据块的第三行包含 nin_i 个整数 ci,1,…,ci,nic_{i, 1}, \ldots, c_{i, n_i}(1≤ci,j≤10121 \le c_{i, j} \le 10^{12}),表示第 ii 个多重集中各元素的副本数量。

保证所有测试用例中 mm 的总和不超过 10510^5,且所有测试用例中所有数据块的 nin_i 总和也不超过 10510^5。

输出格式

For each test case, output the minimum possible anti-beauty of the multiset XX that you can achieve.

对于每个测试用例,输出你能达到的多重集 XX 的最小可能反美感值。

输入输出样例

  • 输入#1

    7
    3
    3 5 6
    10 11 12
    3 3 1
    1 1 3
    12
    4
    2 4 4
    12 13
    1 5
    1
    7 1000 1006
    1000 1001 1002 1003 1004 1005 1006
    147 145 143 143 143 143 142
    1
    2 48 50
    48 50
    25 25
    2
    1 1 1
    1
    1
    1 1 1
    2
    1
    1
    1 1 1
    1
    2
    2
    1 1 1
    1
    1
    2 1 1
    1 2
    1 1
    2
    4 8 10
    11 12 13 14
    3 3 3 3
    2 3 4
    11 12
    2 2

    输出#1

    1
    139
    0
    1
    1
    0
    0

说明/提示

In the first test case, the multisets have the following form:

  1. 10,10,10,11,11,11,12{10, 10, 10, 11, 11, 11, 12}. From this multiset, you need to select between 55 and 66 numbers.
  2. 12,12,12,12{12, 12, 12, 12}. From this multiset, you need to select between 11 and 33 numbers.
  3. 12,13,13,13,13,13{12, 13, 13, 13, 13, 13}. From this multiset, you need to select 44 numbers.

You can select the elements 10,11,11,11,12{10, 11, 11, 11, 12} from the first multiset, 12{12} from the second multiset, and 13,13,13,13{13, 13, 13, 13} from the third multiset. Thus, X=10,11,11,11,12,12,13,13,13,13X = {10, 11, 11, 11, 12, 12, 13, 13, 13, 13}. The size of XX is 1010, the number 1010 appears exactly 11 time in XX, so the anti-beauty of XX is 11. It can be shown that it is not possible to achieve an anti-beauty less than 11.

在第一个测试用例中,多重集合具有以下形式:

  1. 10,10,10,11,11,11,12{10, 10, 10, 11, 11, 11, 12}。从该多重集合中,你需要选出 55 到 66 个数。
  2. 12,12,12,12{12, 12, 12, 12}。从该多重集合中,你需要选出 11 到 33 个数。
  3. 12,13,13,13,13,13{12, 13, 13, 13, 13, 13}。从该多重集合中,你需要选出 44 个数。

你可以从第一个多重集合中选出元素 10,11,11,11,12{10, 11, 11, 11, 12},从第二个多重集合中选出 12{12},从第三个多重集合中选出 13,13,13,13{13, 13, 13, 13}。于是,X=10,11,11,11,12,12,13,13,13,13X = {10, 11, 11, 11, 12, 12, 13, 13, 13, 13}。集合 XX 的大小为 1010,数字 1010 在 XX 中恰好出现 11 次,因此 XX 的反美观度为 11。可以证明,无法得到小于 11 的反美观度。

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

首页