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

Автор __Handle__, история, 5 лет назад, По-английски

I have no idea for this. Can someone help me?

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

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

Think about mo's algorithm. The only think left is to find out how to insert and delete a single number, maintaining the number of such pairs. If you don't have any idea look at my code for more information. Code

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

    Can you explain why are you adding like this: cnt += get(num - k) + get(100000) - get(num + k - 1); UPD: Ok I understood. Sorry

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

      Well it is the number of the pairs with the current number, where the absolute difference is at least k. Because such numbers should be smaller or equal than num — k or greater or equal than num + k.