wadhwasahil's blog

By wadhwasahil, history, 9 years ago, In English

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.

  • Vote: I like it
  • +3
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

use queue in each node to store the ranks

  • »
    »
    9 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    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 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      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 years ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

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