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

Автор SpartanWarrior, история, 3 года назад, По-английски

Can someone please help me on how to approach this Problem

Thanking you in anticipation.

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

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

for query you can use sparse table or segment tree

»
3 года назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится
Hint
Solution
»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
  • »
    »
    10 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I actually am not able to understand with this is O(n). At first glance it seemed O(n^2) to me.

    What I thought was, for every j, the remove function in the tutorial in worst case removes no elements, which is analoguous here to moving the i pointer from j to the start (j times).

    So the no of iterations in the worst case: 1+2+3...n = O(n^2)

    Please let me know if I have made any mistake at any point... Would really appreciate the help...

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

In tutorial, we can easily get max/min when adding an element, but it's hard to remove an element.

How does the tutorial solve it?

It uses two stacks to implement the queue, and get the result of max/min from two of the stack to get the result.

Can we just replace it with other merge function?