Chef has an array
of integers. He asks you queries. For each query, you are given the following:
- An integer .
- An array of size such that .
You need to erase minimum number of elements from such that the bitwise-OR of the remaining elements is at most and no element having index is erased.
For each query, find the maximum number of remaining elements such that the bitwise OR of the remaining elements is at most and no element with index is erased. If it is impossible to get an OR of at most , print .
Note: The bitwise OR of an empty array is considered .
Input Format
- The first line of the input consists of integers and , the number of elements in the array and the number of queries.
- The next line contains space separated integers, the elements of the array . The descriptions of the queries follow.
- The first line of each query consists of integers and , the integer and the number of indices that cannot be erased.
- The last line of each query consists of space separated integers denoting that the elements cannot be erased. Note that, this line is omitted if .
Output Format
Print lines, the answers to each of the queries.
For each query, print -1
if it is impossible to get an OR of at most . Otherwise, print the maximum number of remaining elements.
Constraints
- , such that
- Sum of over all queries does not exceed .
Subtasks
- Subtask 1 (40 points): .
- Subtask 2 (60 points): No additional constraints.
Sample Input 1
3 1
4 3 5
6 0
Sample Output 1
2
Explanation
The given array . In binary representation, . We are given that the size of array is . Thus, we can delete any element of the array .
- Erase elements: The remaining array . Bitwise OR of the remaining elements is . Since , we have to erase some elements of the array.
- Erase element: If we erase the element at index , the remaining array . Bitwise OR of the remaining elements is:
. Since , all the required conditions are satisfied.
Thus, the maximum number of remaining elements is .
Sample Input 2
5 2
14 8 11 6 3
14 1
4
3 2
2 4
Sample Output 2
3
-1
Explanation
The given array . In binary representation, .
Query : We are given that the element at index cannot be erased.
A possible way to satisfy the given conditions is to erase the elements at indices and . Thus, the remaining array would be . The bitwise OR of remaining elements would be which is less than equal to .
It can be proven that the maximum number of remaining elements cannot exceed .Query : We are given that the elements at indices and cannot be erased. In the worst case that we erase all other elements, we are left with . The bitwise OR of these elements is . Thus, it is impossible to erase some elements leaving an OR of at most .
No comments:
Post a Comment