Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

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

problem link I am doing this question using AVL tree but I am not able to handle the duplicate values in the input. First , I thought of using a vector for each node but that will turn out to be a TLE. Any help would be really appreciated.

Thanks in advance.

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

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

use queue in each node to store the ranks

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

    but how will I delete a node ? I mean, if I have a node A (val=10 & rank=1,3,5,10) and its in-order successor node B(val=12 & rank=2,4) . So I have to copy the entire node(val and queue) of node B to node A. Won't it lead to TLE?

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

      yes you are right, i'm sorry.

      i did the implementation and it gives TL on test 3. so there must be another way.

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

      seems like O(nlgn + mlg(n+m)) can't fit in the time limit! after some thinking, i approach a way simpler solution, it works as follows:

      q[x] is a queue that stores all the ranks for value x, to answer query I x just do q[x].push(currentRank) the other queries are the same, you may refer to the code. However it stills TL on the third test. the solution seems to be a way harder.

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

        In my opinion O(nlogn) should pass easily. However , only 11 submissions have been there so far for this problem.