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

Автор shuprog1, 10 лет назад, По-английски

Please suggest an approach to solve this problem. (Problem Link)

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

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

Firstly we have to convert the tree queries into array queries. We can perform a dfs and using start and end times , convert the tree to an array. Then each subtree is a range l to r in the array. Now according to the question we have to count the nodes in the subtree rooted at X with value between l to r. That is a range query in array which can be handled using segment tree.

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

    According to me, it was required to run BFS/DFS from node x and check the heights of all nodes in subtree to be in range [L,R]. I constructed a directed graph and followed this approach which gave me WA. Can you tell why this approach is wrong?