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

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

Hi everyone , I have a question which i faced a lot while implementing a problem and i usually handled it with segment tree but i think it must have an easier way

think that u have a set s

i want to find out number x position in this set

more formally i want s.find(x) — s.begin()

but c++ set can't handle this ! what should i do ? is there any way without using other structures to solve this ?

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

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

Auto comment: topic has been updated by _Ramtin_ (previous revision, new revision, compare).

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

If there are many such 'queries', then transform std::set into a vector. Vector supports upper_bound/lower_bound functions and by subtracting v.begin() you can get the index.

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

    nope i needed an online sorted array for those problems and vector couldn't do that :)

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

      Then you will have to write your own treap. I assume that distance works in linear time and is almost completely useless in your case.

      There are ways to use g++ order statistic tree if you really need it.

»
8 лет назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится
»
8 лет назад, # |
  Проголосовать: нравится -6 Проголосовать: не нравится

Your Big Problem is your little penis!