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

Автор Alwoosh, история, 25 часов назад, По-английски

In the last Educational Round, I implemented next solution for G problem(2043-G - Problem with Queries), and never seen before, solution like this, for online MO problems.

298356157

In the problems, we have to find number of pairs of unequal values in the some range. Also, we have updates, and queries — online.

Firstly, I change our task to find pairs of equal values, and imediatelly think about MO(offline solution of problem). Instead of one supported MO segment, I decided to support 500 MO segments. In the updates, I just update MO segments that have that value inside of segment. And for the second type of queries, firstly I find MO segment that needed less iterations to reach the range from the query.

Update: the solution has been hacked, and I have added a new way to optimize code, if we have a MO segment that needed less than 3000 iterations to reach the range from the query, then we can just pick that MO segment. In another case, if we have less than 500 created MO segments, we create a new segment. If we have create 500 MO segments already and no one don't reached by 3000 iterations, just pick a segment with less iterations(like in the first solution).

298386140

I am curious whether it should pass the tests and about its complexity. Also, have you seen this technique before? Personally, I did not encounter any blogs about this.

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

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

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

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

классное решение, я тоже никогда не видел Online Mo такого вида.

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

50 отрезков почти за такое же время работают

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

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

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

бомбезно

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

Cool technique! Looks like its complexity is amortized $$$O\left(\dfrac{n}{\sqrt{k}}\right)$$$ per query and $$$O(k)$$$ per update, where $$$n$$$ is the length of initial array and $$$k$$$ is the number of so-called "MO segments".

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

    Your solution is very similar to this: split initial array into $$$O\left(\sqrt{k}\right)$$$ blocks and calculate "MO segment" between each pair of blocks. Then for each query use appropriate "MO segment" to answer it in guaranteed $$$O\left(\dfrac{n}{\sqrt{k}}\right)$$$ and then return this "MO segment" back to initial state. Even though it works in guaranteed time, it is probably slower in practice then your amortized solution.

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

Hacked