__Handle__'s blog

By __Handle__, history, 5 years ago, In English

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

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    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 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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.