Блог пользователя nkb-xyz

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

How to efficiently count the number of pairs having a xor b equal to m where 1<=a<=n , 1<=b<=n and n varies 2 to 2e5 and m also varies 1 to n

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

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

Auto comment: topic has been updated by nkb-xyz (previous revision, new revision, compare).

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

Hint: If a and m are fixed, can you find a value of b, such that a ^ b = m?

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

    yeah b = m^a and complexity will be o(n) right?? got it ... it this final like cant we go beyond that like logarithmic or like lesser than this

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

      My bad, you still need to check if the corresponding b is <= n, so n — 1 is not correct, in general it is less than that. So I failed in my attempt to make it better than O(n)

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

      Good job! How many possible values of a are there?

      (Don't overthink the complexity — what you are shooting for is O(n) )

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

        For linear time we can just iterate a from 1 to n and check if the corresponding b is in 1 to n or nah. I think OP is asking for a sublinear algorithm.