Code of http://www.spoj.com/problems/HORRIBLE/ using segment tree with lazy propagation