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

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

Please help me.

This is a problem of segment tree and this is my submission.

Please can someone check this and tell me why this gives TLE.

Thank You.

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

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

Because you use endl.

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

    I changed endl with '\n' but I still got TLE. Solution

    But I just found out that if I pass String s in build functions by reference it doesn't give TLE. Correct Solution

    But I am not able to understand why because we don't need to change s while building the tree? Please tell me this.

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

      Oh right, I did not notice you were passing s by value.

      If you pass s by value, then it gets copied for every build call you make. If you pass by reference, there is only one string. Copying the string is expensive.

      endl is still too slow btw, even if you got accepted with it this time.