0

I could not find any such query. Given a range and the index i, we want to count the numbers in the range that have bit i set.

Eg, range=[6,13] and i=2, ans=4

6 0110

7 0111

8 1000

9 1001

10 1010

11 1011

12 1100

13 1101

Is there a better approach than traversing the range

  • That depends, is this a "one off" query or can you pre-process the array (which makes sense if there are multiple queries with the same data)? – harold Dec 24 '19 at 11:27
  • there is no array of distinct numbers. there are multiple queries for different ranges of the form [l,r]. Also you cannot pre-process as l and r can be as large as 1e18 – Madhuram Jajoo Dec 24 '19 at 11:38
  • Oh I see, the range is literally the integers themselves, no data. That makes it more of a math problem. – harold Dec 24 '19 at 11:53

0 Answers0