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

Автор marius135, 10 лет назад, По-английски

I am interested in knowing if there is a data structure that can offer better than O(log n) average complexity and offers the following 2 operations:

Increment x-> V[x] = 1 (all elements are initially 0) Query (1->y) all query are 1 based...

I know I will have O(n) increases and O(n) queries and want better than O(n log n) total time...

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

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

What is the "query" operation doing — summing, checking if anything in the range is a set bit, or something else entirely?

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

    Summing. For checking if anything in the range has a set bit, one could use rmq and obtain a theoretical O(n) for preprocessing and O(1) query.

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

      You would need RMQ with updates for that. Can it be implemented in linear time?

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

        probably not, I have a few things different though... 1) I know my values are 0 and 1 only 2) I know i have at most n queries and n modifications and I want a total of under O(n log n) so it can be amortized O(n) or even O(n log logn ) 3) All my queries are 1->y which usually does not help... 4) I know the operations from the beginning