CF1903D1.Maximum And Queries (easy version)

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The only difference between the two versions is the constraint on nn and qq, the memory and time limits. You can make hacks only if all versions of the problem are solved.

Theofanis really likes to play with the bits of numbers. He has an array aa of size nn and an integer kk. He can make at most kk operations in the array. In each operation, he picks a single element and increases it by 11.

He found the maximum bitwise AND that array aa can have after at most kk operations.

Theofanis has put a lot of work into finding this value and was very happy with his result. Unfortunately, Adaś, being the evil person that he is, decided to bully him by repeatedly changing the value of kk.

Help Theofanis by calculating the maximum possible bitwise AND for qq different values of kk. Note that queries are independent.

这是该问题的简单版本。两个版本之间的唯一区别在于对 nn 和 qq 的约束,以及内存和时间限制。仅当该问题的所有版本均被解决时,你才可以进行 hack。

Theofanis 非常喜欢玩弄数字的二进制位。他有一个长度为 nn 的数组 aa 和一个整数 kk。他最多可以在数组中执行 kk 次操作。每次操作中,他选择一个元素并将其值加 11。

他找到了在最多执行 kk 次操作后,数组 aa 能达到的最大按位与(bitwise AND)值。

Theofanis 为求出该值付出了大量努力,并对自己的结果感到非常满意。不幸的是,Adaś——这个邪恶的家伙——决定通过反复修改 kk 的值来欺负他。

请帮助 Theofanis 计算在 qq 个不同的 kk 值下所能达到的最大可能的按位与(bitwise AND)值。注意:各次查询相互独立。

输入格式

The first line contains two integers nn and qq (1≤n,q≤1051 \le n, q \le 10^5 and n⋅q≤105n \cdot q \le 10^5) — the size of the array and the number of queries.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1060 \le a_i \le 10^6) — the elements of the array.

Next qq lines describe the queries. The ii-th line contains one integer kik_i (0≤ki≤10180 \le k_i \le 10^{18}) — the number of operations that can be done in the ii-th query.

第一行包含两个整数 nn 和 qq(1≤n,q≤1051 \le n, q \le 10^5 且 n⋅q≤105n \cdot q \le 10^5)—— 分别表示数组的大小和查询次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1060 \le a_i \le 10^6)—— 表示数组的元素。

接下来的 qq 行描述各次查询。第 ii 行包含一个整数 kik_i(0≤ki≤10180 \le k_i \le 10^{18})—— 表示第 ii 次查询中允许执行的操作次数。

输出格式

For each query, print one integer — the maximum bitwise AND that array aa can have after at most kik_i operations.

对于每个查询,输出一个整数——数组 aa 在最多执行 kik_i 次操作后所能达到的最大按位与(bitwise AND)值。

输入输出样例

  • 输入#1

    4 2
    1 3 7 5
    2
    10

    输出#1

    2
    6
  • 输入#2

    3 5
    4 0 2
    9
    8
    17
    1
    3

    输出#2

    5
    4
    7
    0
    1
  • 输入#3

    1 2
    10
    5
    2318381298321

    输出#3

    15
    2318381298331

说明/提示

In the first test case, in the first query, we add 11 in the first and last elements of the array.

Thus, the array becomes [2,3,7,6][2,3,7,6] with bitwise AND equal to 22.

In the second test case, in the first query, we add 11 in the first element, 55 in the second, and 33 in the third and now all the elements are equal to 55.

在第一个测试用例中,第一次查询时,我们在数组的第一个和最后一个元素中各加上 11。

因此,数组变为 [2,3,7,6][2,3,7,6],其按位与(bitwise AND)结果为 22。

在第二个测试用例中,第一次查询时,我们在第一个元素中加上 11,第二个元素中加上 55,第三个元素中加上 33,此时所有元素均等于 55。

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

首页