Hack Protection
Time limit1sMemory limit128 MB
Count the subarrays of the given array whose bitwise XOR equals their bitwise AND.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Prefix sum, Hash map, Binary search
- Solved
- No attempts yet
Problem
Pavel is sending his friend Egor an array of non-negative integers. He wants to be sure that nobody changes the array before Egor receives it, so he computes a checksum, a digest, of the array.
Pavel invented his own digest. For every subarray, compute the bitwise XOR of its elements and the bitwise AND of the same elements, then count the subarrays where the two values are equal. A subarray is one or more consecutive elements of the array.
For example, take the array of four numbers written in binary as 01, 10, 11, 11, which is 1, 2, 3, 3 in decimal. Six of its subarrays have equal XOR and AND. Each of the four single-element subarrays qualifies, because for one number the XOR and the AND are both that number. The first through third elements give XOR 0 and AND 0. The second through fourth elements give XOR 10 and AND 10 in binary, which is 2 in decimal.
Compute this digest of the given array.
Input
The first line contains one integer ().
The second line contains non-negative integers () written in decimal notation and separated by spaces.
Output
On the first line print Pavel's digest of the given array, that is, the number of subarrays whose bitwise XOR equals their bitwise AND.
Hint
The sample input is the array described in the statement.