The reason you get TLE is the inherent slow nature of Python. However since you are following my solution, I can explain how my implementation is faster than yours.
- I am using an iterative segment tree instead of a recursive one. I have provided a couple of relevant links under your other question.
- I am not using lazy propagation. You could say I am using the lazy, but not the propagation. How does this work? We break up the range update into pieces and store them at the relevant nodes just like in lazy propagation. However there is no need to propagate them here. Instead, while querying on a point we can gather all pending updates on it on the path from the leaf to the root. Note that this trick works for only specific types of updates, so this is NOT a substitute for lazy propagation in general.
Feel free to ask if something is not clear!
UPDATE: About the segment tree usage-
Take a look at the picture below. Consider that as the sum segment tree. I have noted below each node what range it covers. At first all values are 0, so consider the empty cells as 0.
The first update is on [1…7] of value 5. Just like in lazy propagation, the range [0…7] is distributed over the segment tree and the value 5 stored on the correct nodes.
The next update is on [2…5] of value 3. Once again the correct nodes are found, and 3 is added to the currently stored values in those nodes.
Now suppose you want to query on any index, say 5. For the query, just travel the path from the root to the index and add up all the values you find. For index 5, the query result is 5+3 = 8, which is correct. Try the same for the other indices to check for yourself. It’s quite easy to see how it works, and it is definitely simpler than implementing lazy propagation