[Solution] Binod CodeChef Solution | Solution CodeChef
Problem
A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.
You are given an array of elements. Process queries on this array, of the following form:
- Each query contains integers . It is guaranteed that .
- The answer to a query is the number of pairs such that:
- and
- has its -th bit set. Here denotes the bitwise XOR operation.
Note: An integer is said to have its -th bit set if the (unique) binary representation of contains . For example, has its zeroth and second bits set but not the first, while has only its fourth bit set.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains two space-separated integers and — the number of elements in array and number of queries, respectively.
- The second line of each test case contains space-separated integers .
- The next lines describe queries. The -th of these lines contains space-separated integers — the parameters described in the statement.
Output Format
For each test case, output lines.The -th of these lines should be the answer to the -th query.
Explanation:
Test case : The array is .
- Query : the ranges are and , and . There are three pairs of : .
- has its first bit set
- doesn't have its first bit set
- has its first bit set
- So, the answer is .
- Query : the ranges are and , and now . This time, there are pairs of indices. Of them, it can be verified that and are the ones that satisfy the given condition.
No comments:
Post a Comment