rebel_roar's blog

By rebel_roar, history, 2 years ago, In English

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.

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

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

Because you use endl.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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.