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

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

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

Problem: 13101 — Tobby On Tree

Solution: Using HLD or Using HLD

The problem is, You are given a tree. In every node, there is a value assigned to it and also given some query.

Query:

1 u v: compute the gcd on the path from u to v.

2 u x: Change the value of the node u to x.

I have written a code of HLD and submitted but it gave me TLE. I haven't found anything in the code to optimize.

In this case, I need help to optimize the code if it is possible. Please help me if you are free.

Thanks in Advance :)

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

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

I haven't found anything in the code to optimize.

What have you tried in the first place? Have you tried random test cases? Have you tried benchmarking certain functions in your code?

Your code is over 150 lines long and is very complex. So I doubt anyone is going to read it.

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

    Thanks for the comment.

    I have tried random test cases but there is no problem in the result. As the problem is how to reduce the complexity of my code, I can't figure out the way in which the code will be more efficient than before.

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

I guess the problem may be with fresh() function. There may be so many test cases with n is small in each and you are resetting $$$1.5*10^5$$$ values to something. I don't see any potential TLE risk on HLD and segment tree part.

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

    I have updated my fresh() function but nothing much improved :(

    fresh()