A16285 | Maximum And Queries (easy version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This is the easy version of the problem. The only difference between the two versions is the constraint on $n$ and $q$ , 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 $a$ of size $n$ and an integer $k$ . He can make at most $k$ operations in the array. In each operation, he picks a single element and increases it by $1$ .
He found the maximum [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) that array $a$ can have after at most $k$ 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 $k$ .
Help Theofanis by calculating the maximum possible [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) for $q$ different values of $k$ . Note that queries are independent.
Theofanis really likes to play with the bits of numbers. He has an array $a$ of size $n$ and an integer $k$ . He can make at most $k$ operations in the array. In each operation, he picks a single element and increases it by $1$ .
He found the maximum [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) that array $a$ can have after at most $k$ 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 $k$ .
Help Theofanis by calculating the maximum possible [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) for $q$ different values of $k$ . Note that queries are independent.
输入格式
The first line contains two integers $n$ and $q$ ( $1 \le n, q \le 10^5$ and $n \cdot q \le 10^5$ ) — the size of the array and the number of queries.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \le a_i \le 10^6$ ) — the elements of the array.
Next $q$ lines describe the queries. The $i$ -th line contains one integer $k_i$ ( $0 \le k_i \le 10^{18}$ ) — the number of operations that can be done in the $i$ -th query.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \le a_i \le 10^6$ ) — the elements of the array.
Next $q$ lines describe the queries. The $i$ -th line contains one integer $k_i$ ( $0 \le k_i \le 10^{18}$ ) — the number of operations that can be done in the $i$ -th query.
输出格式
For each query, print one integer — the maximum bitwise AND that array $a$ can have after at most $k_i$ operations.
输入输出样例
输入 #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 $1$ in the first and last elements of the array.
Thus, the array becomes $[2,3,7,6]$ with bitwise AND equal to $2$ .
In the second test case, in the first query, we add $1$ in the first element, $5$ in the second, and $3$ in the third and now all the elements are equal to $5$ .
Thus, the array becomes $[2,3,7,6]$ with bitwise AND equal to $2$ .
In the second test case, in the first query, we add $1$ in the first element, $5$ in the second, and $3$ in the third and now all the elements are equal to $5$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted