CF1461D.Divide and Summarize

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Mike received an array aa of length nn as a birthday present and decided to test how pretty it is.

An array would pass the ii-th prettiness test if there is a way to get an array with a sum of elements totaling sis_i, using some number (possibly zero) of slicing operations.

An array slicing operation is conducted in the following way:

  • assume mid=⌊max(array)+min(array)2⌋mid = \lfloor\frac{max(array) + min(array)}{2}\rfloor, where maxmax and minmin — are functions that find the maximum and the minimum array elements. In other words, midmid is the sum of the maximum and the minimum element of arrayarray divided by 22 rounded down.
  • Then the array is split into two parts left\mathit{left} and rightright. The left\mathit{left} array contains all elements which are less than or equal midmid, and the rightright array contains all elements which are greater than midmid. Elements in left\mathit{left} and rightright keep their relative order from arrayarray.
  • During the third step we choose which of the left\mathit{left} and rightright arrays we want to keep. The chosen array replaces the current one and the other is permanently discarded.

You need to help Mike find out the results of qq prettiness tests.

Note that you test the prettiness of the array aa, so you start each prettiness test with the primordial (initial) array aa. Thus, the first slice (if required) is always performed on the array aa.

迈克收到了一个长度为 nn 的数组 aa 作为生日礼物,并决定测试它的“美观度”。

若存在一种方式,通过对数组进行若干次(可能为零次)切片操作,得到一个元素和恰好为 sis_i 的数组,则该数组通过第 ii 个美观度测试。

一次数组切片操作按如下方式进行:

  • 设 mid=⌊max⁡(array)+min⁡(array)2⌋mid = \left\lfloor\frac{\max(\text{array}) + \min(\text{array})}{2}\right\rfloor,其中 max⁡\max 和 min⁡\min 分别表示求数组中最大值与最小值的函数。换言之,midmid 是数组最大值与最小值之和除以 22 后向下取整。
  • 然后将原数组划分为两个子数组:left\mathit{left} 和 right\mathit{right}。left\mathit{left} 包含所有小于等于 midmid 的元素,right\mathit{right} 包含所有大于 midmid 的元素;left\mathit{left} 和 right\mathit{right} 中的元素均保持其在原数组中的相对顺序。
  • 第三步中,我们选择保留 left\mathit{left} 或 right\mathit{right} 中的一个子数组,被选中的子数组将取代当前数组,另一个则被永久丢弃。

你需要帮助迈克判断 qq 个美观度测试的结果。

注意:你始终是对原始数组 aa 进行美观度测试,因此每次美观度测试都从初始数组 aa 开始。也就是说,第一次切片操作(如果需要的话)总是作用于数组 aa。

输入格式

Each test contains one or more test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100).

The first line of each test case contains two integers nn and qq (1≤n,q≤105)(1 \le n, q \le 10^5) — the length of the array aa and the total number of prettiness tests.

The second line of each test case contains nn integers a1,a2,...,ana_1, a_2, ..., a_n (1≤ai≤106)(1 \le a_i \le 10^6) — the contents of the array aa.

Next qq lines of each test case contain a single integer sis_i (1≤si≤109)(1 \le s_i \le 10^9) — the sum of elements which Mike wants to get in the ii-th test.

It is guaranteed that the sum of nn and the sum of qq does not exceed 10510^5 (∑n,∑q≤105\sum n, \sum q \le 10^5).

每个测试包含一个或多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。

每个测试用例的第一行包含两个整数 nn 和 qq(1≤n,q≤1051 \le n, q \le 10^5)—— 分别表示数组 aa 的长度以及总共的“美观度”测试次数。

每个测试用例的第二行包含 nn 个整数 a1,a2,...,ana_1, a_2, ..., a_n(1≤ai≤1061 \le a_i \le 10^6)—— 表示数组 aa 的内容。

每个测试用例接下来的 qq 行,每行包含一个整数 sis_i(1≤si≤1091 \le s_i \le 10^9)—— 表示 Mike 在第 ii 次测试中希望得到的元素之和。

保证所有测试用例的 nn 之和以及所有测试用例的 qq 之和均不超过 10510^5(即 ∑n,∑q≤105\sum n, \sum q \le 10^5)。

输出格式

Print qq lines, each containing either a "Yes" if the corresponding prettiness test is passed and "No" in the opposite case.

输出 qq 行,每行包含一个字符串:若对应的美观性测试通过,则输出 "Yes";否则输出 "No"。

输入输出样例

  • 输入#1

    2
    5 5
    1 2 3 4 5
    1
    8
    9
    12
    6
    5 5
    3 1 3 1 3
    1
    2
    3
    9
    11

    输出#1

    Yes
    No
    Yes
    No
    Yes
    No
    Yes
    No
    Yes
    Yes

说明/提示

Explanation of the first test case:

  1. We can get an array with the sum s1=1s_1 = 1 in the following way:

    1.1 a=[1,2,3,4,5]a = [1, 2, 3, 4, 5], mid=1+52=3mid = \frac{1+5}{2} = 3, left=[1,2,3]\mathit{left} = [1, 2, 3], right=[4,5]right = [4, 5]. We choose to keep the left\mathit{left} array.

    1.2 a=[1,2,3]a = [1, 2, 3], mid=1+32=2mid = \frac{1+3}{2} = 2, left=[1,2]\mathit{left} = [1, 2], right=[3]right = [3]. We choose to keep the left\mathit{left} array.

    1.3 a=[1,2]a = [1, 2], mid=1+22=1mid = \frac{1+2}{2} = 1, left=[1]\mathit{left} = [1], right=[2]right = [2]. We choose to keep the left\mathit{left} array with the sum equalling 11.

  2. It can be demonstrated that an array with the sum s2=8s_2 = 8 is impossible to generate.

  3. An array with the sum s3=9s_3 = 9 can be generated in the following way:

    3.1 a=[1,2,3,4,5]a = [1, 2, 3, 4, 5], mid=1+52=3mid = \frac{1+5}{2} = 3, left=[1,2,3]\mathit{left} = [1, 2, 3], right=[4,5]right = [4, 5]. We choose to keep the rightright array with the sum equalling 99.

  4. It can be demonstrated that an array with the sum s4=12s_4 = 12 is impossible to generate.

  5. We can get an array with the sum s5=6s_5 = 6 in the following way:

    5.1 a=[1,2,3,4,5]a = [1, 2, 3, 4, 5], mid=1+52=3mid = \frac{1+5}{2} = 3, left=[1,2,3]\mathit{left} = [1, 2, 3], right=[4,5]right = [4, 5]. We choose to keep the left\mathit{left} with the sum equalling 66.

Explanation of the second test case:

  1. It can be demonstrated that an array with the sum s1=1s_1 = 1 is imposssible to generate.

  2. We can get an array with the sum s2=2s_2 = 2 in the following way:

    2.1 a=[3,1,3,1,3]a = [3, 1, 3, 1, 3], mid=1+32=2mid = \frac{1+3}{2} = 2, left=[1,1]\mathit{left} = [1, 1], right=[3,3,3]right = [3, 3, 3]. We choose to keep the left\mathit{left} array with the sum equalling 22.

  3. It can be demonstrated that an array with the sum s3=3s_3 = 3 is imposssible to generate.

  4. We can get an array with the sum s4=9s_4 = 9 in the following way:

    4.1 a=[3,1,3,1,3]a = [3, 1, 3, 1, 3], mid=1+32=2mid = \frac{1+3}{2} = 2, left=[1,1]\mathit{left} = [1, 1], right=[3,3,3]right = [3, 3, 3]. We choose to keep the rightright array with the sum equalling 99.

  5. We can get an array with the sum s5=11s_5 = 11 with zero slicing operations, because array sum is equal to 1111.

第一个测试用例的说明:

  1. 我们可以通过如下方式得到一个和为 s1=1s_1 = 1 的数组:

    1.1 a=[1,2,3,4,5]a = [1, 2, 3, 4, 5],mid=1+52=3mid = \frac{1+5}{2} = 3,left=[1,2,3]\mathit{left} = [1, 2, 3],right=[4,5]right = [4, 5]。我们选择保留 left\mathit{left} 数组。

    1.2 a=[1,2,3]a = [1, 2, 3],mid=1+32=2mid = \frac{1+3}{2} = 2,left=[1,2]\mathit{left} = [1, 2],right=[3]right = [3]。我们选择保留 left\mathit{left} 数组。

    1.3 a=[1,2]a = [1, 2],mid=1+22=1mid = \frac{1+2}{2} = 1,left=[1]\mathit{left} = [1],right=[2]right = [2]。我们选择保留 left\mathit{left} 数组,其和为 11。

  2. 可以证明,无法生成和为 s2=8s_2 = 8 的数组。

  3. 和为 s3=9s_3 = 9 的数组可通过如下方式生成:

    3.1 a=[1,2,3,4,5]a = [1, 2, 3, 4, 5],mid=1+52=3mid = \frac{1+5}{2} = 3,left=[1,2,3]\mathit{left} = [1, 2, 3],right=[4,5]right = [4, 5]。我们选择保留 rightright 数组,其和为 99。

  4. 可以证明,无法生成和为 s4=12s_4 = 12 的数组。

  5. 我们可以通过如下方式得到一个和为 s5=6s_5 = 6 的数组:

    5.1 a=[1,2,3,4,5]a = [1, 2, 3, 4, 5],mid=1+52=3mid = \frac{1+5}{2} = 3,left=[1,2,3]\mathit{left} = [1, 2, 3],right=[4,5]right = [4, 5]。我们选择保留 left\mathit{left} 数组,其和为 66。

第二个测试用例的说明:

  1. 可以证明,无法生成和为 s1=1s_1 = 1 的数组。

  2. 我们可以通过如下方式得到一个和为 s2=2s_2 = 2 的数组:

    2.1 a=[3,1,3,1,3]a = [3, 1, 3, 1, 3],mid=1+32=2mid = \frac{1+3}{2} = 2,left=[1,1]\mathit{left} = [1, 1],right=[3,3,3]right = [3, 3, 3]。我们选择保留 left\mathit{left} 数组,其和为 22。

  3. 可以证明,无法生成和为 s3=3s_3 = 3 的数组。

  4. 我们可以通过如下方式得到一个和为 s4=9s_4 = 9 的数组:

    4.1 a=[3,1,3,1,3]a = [3, 1, 3, 1, 3],mid=1+32=2mid = \frac{1+3}{2} = 2,left=[1,1]\mathit{left} = [1, 1],right=[3,3,3]right = [3, 3, 3]。我们选择保留 rightright 数组,其和为 99。

  5. 我们可以在不进行任何切分操作的情况下得到一个和为 s5=11s_5 = 11 的数组,因为原数组的和即为 1111。

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

首页