Codeforces и Polygon могут быть недоступны в период с 23 мая, 7:00 (МСК) по 23 мая, 11:00 (МСК) в связи с проведением технических работ. ×

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

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

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
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится 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.

»
3 года назад, # |
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