CF2161G.Bitwise And Equals
NOI/NOI+/CTSC
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is an array of integers a1,a2,…,an, and there is an integer X.
You may perform the following operation zero or more times:
- Select i, and increase ai by one.
Let a′ be the final state of the array. Your goal is to perform the operation above the smallest number of times such that a1′&a2′&…&an′=X. & denotes the bitwise AND operation.
There are q such query integers X: X1,X2,…,Xq. Compute the answer for each X=Xi. Note that all queries are processed separately and independently, from the same initial state a.
给定一个整数数组 a1,a2,…,an 和一个整数 X。
你可以执行以下操作零次或多次:
- 选择下标 i,并将 ai 的值加一。
设 a′ 为数组的最终状态。你的目标是执行上述操作尽可能少的次数,使得 a1′&a2′&…&an′=X。其中 & 表示按位与运算。
共有 q 个这样的查询整数 X:X1,X2,…,Xq。请对每个 X=Xi 计算对应的答案。注意:所有查询均独立处理,且均从相同的初始数组 a 出发。
输入格式
The first line contains integers n and q (2≤n≤200000, 1≤q≤200000) — the length of the array and the number of queries.
The second line contains integers a1,a2,…,an (for each i, 0≤ai<220).
The next q lines each contain a single integer Xi (0≤Xi<220).
第一行包含两个整数 n 和 q(2≤n≤200000,1≤q≤200000)—— 分别表示数组的长度和查询次数。
第二行包含 n 个整数 a1,a2,…,an(对每个 i,满足 0≤ai<220)。
接下来的 q 行每行包含一个整数 Xi(0≤Xi<220)。
输出格式
For each query i out of q, print the smallest number of operations to get to the array a′ such that a1′&a2′&…&an′=Xi.
It's possible to show, that it's always possible to obtain such array a′ in finite number of operations.
对于 q 个查询中的每一个查询 i,输出使得数组 a′ 满足 a1′&a2′&…&an′=Xi 所需的最少操作次数。
可以证明,总能在有限次操作内得到满足条件的数组 a′。
输入输出样例
输入#1
5 4 6 4 7 5 4 0 2 4 6
输出#1
1 8 0 5
说明/提示
For the first query, you can increase i=3 (ai=7) and get the array a=[6,4,8,5,4], then 6&4&8&5&4=0.
For the third query, original array already matches condition: 6&4&7&5&4=4.
对于第一个查询,你可以将 i=3(即 ai=7)增加,得到数组 a=[6,4,8,5,4],此时 6&4&8&5&4=0。
对于第三个查询,原数组已满足条件:6&4&7&5&4=4。
输入解题思路,AI测评打分。不知道怎么写?