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

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

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
  • Проголосовать: не нравится

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

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

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

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

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

you too can use sqrt descomposition — mipt item 4.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 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:)