I_love_HellHoleStudios's blog

By I_love_HellHoleStudios, history, 4 years ago, In English

I don't know if this trick was introduced or named earlier. But I found it interesting and decided to write a blog about it. The trick is simple and I wrote the blog simple too. Hope you don't get confused.

Link

Please ignore the Chinese interface.

| Write comment?
»
4 years ago, # |
  Vote: I like it +13 Vote: I do not like it

Using set seems overcomplicated because you can solve the problem mentioned in the blog without set at all just keeping current minimum and delta.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    +1.

    The author should probably specify that a set could be used if adding a 4th operation like "check membership" (i.e. checking for $$$x$$$ corrresponds to searching the set for $$$x-\delta$$$)

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes, that would have sense with such operation.

»
4 years ago, # |
  Vote: I like it +60 Vote: I do not like it

This trick indeed has a name, it's offset. It allows adding something to all elements of a set.

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

I dont understand how to execute operation 1, how is the delta added to all of the elements in the set?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    [1, 2, 3] + 2 = [3, 4, 5]

»
4 years ago, # |
  Vote: I like it +18 Vote: I do not like it
»
4 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Might be irrelevant but, Here's the same question but with Xor as an operation: For the Curious Ones!

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

Wow, the trick is amazing trick. Something new for me to learn today.

This trick using set will be more useful when there is one more query to be performed: delete element X. Just remove element (X − δ) from the set or treemap (in Java), and there you go.