Special Bit Numbers

4.4

23 votes
Basic Programming, Bit Manipulation, Bit manipulation, Easy, Prefix sum, Prefix-Sum
Problem

A number is known as special bit number if its binary representation contains atleast two consecutive 1's or set bits. For example with binary representation is a special bit number. Similarly is also a special bit number as it contains atleast two consecutive set bits or ones.

Now the problem is, You are given an Array of  integers and queries. Each query is defined by two integers , . You have to output the count of special bit numbers in the range to .

Input

Contains integer , no of Array elements and - Total Number of Queries.

Next line contains integers defining Array elements.

Next lines contains Queries of the type

Output

Output   lines containing answer for the ith Query.

Constraints

Sample Input
5 3
3 5 1 12 7
1 3
2 3
1 5
Sample Output
1
0
3
Time Limit: 2.5
Memory Limit: 256
Source Limit:
Explanation

In Query range is  and there is only one number with consecutive set bits is ; So ans is .

In Query range is  and there is no number is there with consecutive set bits. So ans is .

In Query range is and there are 3 numbers with consecutive bits set i.e , and .

Editor Image

?