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

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

This problem I meet very often: there is a set, in which we can add element, also we can erase any element. The problem is to count the number of elements less then x.

Sure, the problem can be solved with treap or something like that, but can it be solved with std::set or other already released data structures?

Any ideas?

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

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

It can be solved with C++ SGI STL tree. link

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

STL policy based data structures: order_of_key() is what you're looking for.

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

you too can use sqrt descomposition — mipt item 4.

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

Actually, if the problem allows that you can doing this work offline, you can easily solve it by using Binary Indexed Tree and Hashing:)

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

    yes! you too can use online segment tree on air! (update and query in [1, maxElement]). O(q logmaxElement). This can be implemented without pointers!

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

      If Max Element is too big to store in an array:

      1- Online: You can use dynamic segment tree or any variation of it.

      2- Offline: You can use index compression with regular BIT.