Iterative Segment Trees

I first learned about the segment trees from e-maxx link. It is explained quite well and is very intuitive to understand. The implementation (recursive) is however not well suited to use in a short contest environment. Recently, I read a blog on codeforces link. The implementation is iterative and is quite handy and can be easily modified for various problems.


Yeah but lazy propagation would be a pain in a$$ to implement with this…

I’ve tried this implementation, and even tho it’s short and good at times… but still i prefer the classic implementation because It’s easy to debug + lazy propagation can be added with a few lines of code.

For short contests, you can save the template beforehand