CF1496B.Max and Mex

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a multiset SS initially consisting of nn distinct non-negative integers. A multiset is a set, that can contain some elements multiple times.

You will perform the following operation kk times:

  • Add the element ⌈a+b2⌉\lceil\frac{a+b}{2}\rceil (rounded up) into SS, where a=mex⁡(S)a = \operatorname{mex}(S) and b=max⁡(S)b = \max(S). If this number is already in the set, it is added again.

Here max⁡\operatorname{max} of a multiset denotes the maximum integer in the multiset, and mex⁡\operatorname{mex} of a multiset denotes the smallest non-negative integer that is not present in the multiset. For example:

  • mex⁡(1,4,0,2)=3\operatorname{mex}({1,4,0,2})=3;
  • mex⁡(2,5,1)=0\operatorname{mex}({2,5,1})=0.

Your task is to calculate the number of distinct elements in SS after kk operations will be done.

给你一个多重集 SS,初始时包含 nn 个互不相同的非负整数。多重集是一种允许元素重复出现的集合。

你将执行以下操作 kk 次:

  • 向 SS 中添加元素 ⌈a+b2⌉\lceil\frac{a+b}{2}\rceil(向上取整),其中 a=mex⁡(S)a = \operatorname{mex}(S),b=max⁡(S)b = \max(S)。若该数已存在于集合中,则仍将其再次加入(即允许重复)。

此处,多重集的 max⁡\operatorname{max} 表示该多重集中最大的整数;多重集的 mex⁡\operatorname{mex} 表示未出现在该多重集中的最小非负整数。例如:

  • mex⁡(1,4,0,2)=3\operatorname{mex}({1,4,0,2})=3;
  • mex⁡(2,5,1)=0\operatorname{mex}({2,5,1})=0。

你的任务是计算执行 kk 次操作后,SS 中不同元素的个数。

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001\le t\le 100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn, kk (1≤n≤1051\le n\le 10^5, 0≤k≤1090\le k\le 10^9) — the initial size of the multiset SS and how many operations you need to perform.

The second line of each test case contains nn distinct integers a1,a2,…,ana_1,a_2,\dots,a_n (0≤ai≤1090\le a_i\le 10^9) — the numbers in the initial multiset.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001\le t\le 100),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤1051\le n\le 10^5,0≤k≤1090\le k\le 10^9),分别表示多重集 SS 的初始大小以及需要执行的操作次数。

每个测试用例的第二行包含 nn 个互不相同的整数 a1,a2,…,ana_1,a_2,\dots,a_n(0≤ai≤1090\le a_i\le 10^9),即初始多重集中的数字。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

For each test case, print the number of distinct elements in SS after kk operations will be done.

对于每个测试用例,输出执行 kk 次操作后集合 SS 中不同元素的个数。

输入输出样例

  • 输入#1

    5
    4 1
    0 1 3 4
    3 1
    0 1 4
    3 0
    0 1 4
    3 2
    0 1 2
    3 2
    1 2 3

    输出#1

    4
    4
    3
    5
    3

说明/提示

In the first test case, S=0,1,3,4S={0,1,3,4}, a=mex⁡(S)=2a=\operatorname{mex}(S)=2, b=max⁡(S)=4b=\max(S)=4, ⌈a+b2⌉=3\lceil\frac{a+b}{2}\rceil=3. So 33 is added into SS, and SS becomes 0,1,3,3,4{0,1,3,3,4}. The answer is 44.

In the second test case, S=0,1,4S={0,1,4}, a=mex⁡(S)=2a=\operatorname{mex}(S)=2, b=max⁡(S)=4b=\max(S)=4, ⌈a+b2⌉=3\lceil\frac{a+b}{2}\rceil=3. So 33 is added into SS, and SS becomes 0,1,3,4{0,1,3,4}. The answer is 44.

在第一个测试用例中,S=0,1,3,4S={0,1,3,4},a=mex⁡(S)=2a=\operatorname{mex}(S)=2,b=max⁡(S)=4b=\max(S)=4,⌈a+b2⌉=3\lceil\frac{a+b}{2}\rceil=3。因此将 33 加入 SS,SS 变为 0,1,3,3,4{0,1,3,3,4}。答案为 44。

在第二个测试用例中,S=0,1,4S={0,1,4},a=mex⁡(S)=2a=\operatorname{mex}(S)=2,b=max⁡(S)=4b=\max(S)=4,⌈a+b2⌉=3\lceil\frac{a+b}{2}\rceil=3。因此将 33 加入 SS,SS 变为 0,1,3,4{0,1,3,4}。答案为 44。

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

首页