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

Автор catlak_profesor_mfb, 9 лет назад, По-английски
  • Проголосовать: нравится
  • +38
  • Проголосовать: не нравится

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

Now test to see how large the N has to be for it to be faster than segment trees ;p Though I have to admit, I didn't think it could be made so compact.

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

    Well for N=100000 it is definetely faster :D To test it just overload the < operator and there you go. You can use it with everything as long as you overload < operator. The query returns the position of the minimum.

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

    And I didnt try to optimize it. I just stopped coding when it worked

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

    I think it is faster for N>15000 or something like that. I looked at 282-1-D(birthday) problems test cases

»
9 лет назад, # |
  Проголосовать: нравится +35 Проголосовать: не нравится
ans=min(ans,lookup[sblock[t]&(~(((1<<(l-(r1*lg+lg)))-1)<<(r1*lg+(lg<<1)-l)))]+r1*lg+lg);

That looks really nice :)

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

You split array into blocks of size , then build sparse table for each block and for all blocks. Am I right?

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

    Yes you are right

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

      But I dont actually build a sparse table like in regular rmq for the small blocks

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

      then there are sparse tables, each of size . Therefore total complexity equals to .

      In order to build O(N) algorithm you have to go further and group blocks by its types, such that blocks with equal types will have equal sparse tables. It is exactly what Farach-Colton and Bender did

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

        İt is not O(N) bits memory. İt is O(N) in a 32bit system.

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

        As you can see I take 4 vectors, one of them holds the data which is O(N) and N/logN integers in another vector, N integers in another one and 2^(logN) integers which is N in another vector so total memory is O(N)

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

        You are wrong with that part. The small blocks arent sparse tables. Please pay more attention to the code

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

        If you are not satisfied please put a variable in every loop and increment it. And test it with different N. You will see a linear increase.

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

double post

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

"block" is a sparse table for log(n) blocks of "data". Right? What do "sblock" and "lookup" exactly do?

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

Nice One! But not efficient for large value of N.

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

Read the topic here e-maxx.ru/algo