CF2267F1.XOR Transformations (Easy Version)

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The difference between the versions is that in this version, the constraints on nn and qq are smaller. You can make hacks only if you have solved all versions of this problem.

For an array bb consisting of mm integers, define a transformation as follows:

  • Write down the values bi⊕bjb_i\oplus b_j for all 1≤i<j≤m1\le i\lt j\le m, where ⊕\oplus denotes the bitwise XOR operation..
  • Take the mm smallest among the written values.
  • Replace the elements of the array with the taken mm values.

For example, consider the transformation of the array [6,7,8,9,15][6, 7, 8, 9, 15]. We write down the values 1,1,6,7,8,9,14,14,15,151, 1, 6, 7, 8, 9, 14, 14, 15, 15. After the transformation, the array becomes [1,1,6,7,8][1, 1, 6, 7, 8] — the 55 smallest elements.

You are given an array aa consisting of nn non-negative integers. Let max⁡(a)\max(a) denote the maximum element of the array aa, and min⁡(a)\min(a) — the minimum. Your task is to answer qq queries, each of which gives you one integer xx. For each query, find the value of max⁡(a)−min⁡(a)\max(a) - \min(a) after xx transformations on the array. Note that the queries are independent, i.e. before each query, the array aa is restored to its original state.

这是该问题的简单版本。两个版本的区别在于,本版本中 nn 和 qq 的约束更小。仅当您已解决该问题的所有版本后,才可进行 hack。

对于一个由 mm 个整数组成的数组 bb,定义如下变换:

  • 写出所有满足 1≤i<j≤m1 \le i < j \le m 的 bi⊕bjb_i \oplus b_j 的值,其中 ⊕\oplus 表示按位异或(XOR)运算;
  • 取出所写出的值中最小的 mm 个;
  • 将数组的元素替换为这 mm 个选出的值。

例如,考虑对数组 [6,7,8,9,15][6, 7, 8, 9, 15] 进行变换:我们写出的值为 1,1,6,7,8,9,14,14,15,151, 1, 6, 7, 8, 9, 14, 14, 15, 15。变换后,数组变为 [1,1,6,7,8][1, 1, 6, 7, 8] —— 即其中最小的 55 个元素。

给定一个由 nn 个非负整数组成的数组 aa。记 max⁡(a)\max(a) 为数组 aa 的最大值,min⁡(a)\min(a) 为其最小值。您的任务是回答 qq 个查询,每个查询给出一个整数 xx。对每个查询,请计算对数组 aa 执行 xx 次上述变换后,max⁡(a)−min⁡(a)\max(a) - \min(a) 的值。注意,各查询相互独立,即每次查询前,数组 aa 都会恢复为原始状态。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The first line of each test case contains two integers nn and qq (5≤n≤2000,1≤q≤20005\le n\le 2000, 1\le q\le 2000) — the size of the array and the number of queries.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai<2300\le a_i\lt 2^{30}).

The next qq lines of each test case contain an integer xx (0≤x<2300\le x\lt 2^{30}).

It is guaranteed that the sum of nn and the sum of qq over all test cases do not exceed 20002000.

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

每个测试用例的第一行包含两个整数 nn 和 qq(5≤n≤2000, 1≤q≤20005\le n\le 2000,\ 1\le q\le 2000)——分别表示数组的大小和查询次数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai<2300\le a_i\lt 2^{30})。

每个测试用例的接下来 qq 行,每行包含一个整数 xx(0≤x<2300\le x\lt 2^{30})。

保证所有测试用例的 nn 之和与 qq 之和均不超过 20002000。

输出格式

For each test case, output qq integers — the answer to each query.

对于每个测试用例,输出 qq 个整数——即每个查询的答案。

输入输出样例

  • 输入#1

    4
    5 1
    0 0 1 1 1
    1
    5 2
    6 7 8 9 15
    0
    1
    8 2
    102 92 15 19 25 54 62 36
    2
    1
    10 1
    56 73 81 23 17 92 50 34 67 78
    2

    输出#1

    1
    9
    7
    12
    31
    7

说明/提示

In the first test case, after one transformation, the array becomes [0,0,0,0,1][0, 0, 0, 0, 1]. Here max⁡(a)−min⁡(a)=1−0=1\max(a) - \min(a) = 1 - 0 = 1.

In the second test case, the initial array is [6,7,8,9,15][6, 7, 8, 9, 15]. Initially, max⁡(a)−min⁡(a)=15−6=9\max(a) - \min(a) = 15 - 6 = 9. After the transformation, the array becomes [1,1,6,7,8][1, 1, 6, 7, 8], where max⁡(a)−min⁡(a)=8−1=7\max(a) - \min(a) = 8 - 1 = 7.

在第一个测试用例中,经过一次变换后,数组变为 [0,0,0,0,1][0, 0, 0, 0, 1]。此时 max⁡(a)−min⁡(a)=1−0=1\max(a) - \min(a) = 1 - 0 = 1。

在第二个测试用例中,初始数组为 [6,7,8,9,15][6, 7, 8, 9, 15]。初始时,max⁡(a)−min⁡(a)=15−6=9\max(a) - \min(a) = 15 - 6 = 9。变换后,数组变为 [1,1,6,7,8][1, 1, 6, 7, 8],此时 max⁡(a)−min⁡(a)=8−1=7\max(a) - \min(a) = 8 - 1 = 7。

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

首页