Блог пользователя triggered_

Автор triggered_, история, 4 года назад, По-английски

Q.Find the number of pairs in the array whose bitwise AND is greater then K?

Size of Array: N=5*(10^5)

Elements in Array: (10^9)>=a[i]>=1

Range for K: (10^9)>=K>=0

Expected Time Complexity: O(N) or O(NlogN)

  • Проголосовать: нравится
  • -16
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

It's better to add your approach to the blog than just posting a question. A possible approach could be using some tree structure to store the numbers you have seen so far and somehow traverse the tree to find the count of numbers whose AND with the current element will be > K.

»
4 года назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

You can solve this using SOS dp. Iterate over i, now we want to find j such that a[i] & a[j] >= K. It's easy to see that there are log masks such that a[i] & a[j] >= K is equivalent to a[j] includes one if the masks(a[j] & mask == mask). This can be solved using sum over subset dp