I have a question with a lot of queries which are of four types:
Add to range.
Initialize a range.
Multiply a range with scalar.
Find running sum over a range.
Since queries are in huge numbers I have to use segment tree with lazy propagation but I am stuck on how to use lazy propagation on more than 2 types of queries. How would I be able to identify that when updates are to be made later, then what type of update(i.e. addition, multiplication, initializing) is to be made?
You could possibly give the Update funtcion another argument, call it Query. Depending on the value of that argument, the corresponding operation is done.
For additions and multiplications, the information for the lazy propagation can be contained in two fields:
Let A be the initial value of the leaf and there is an arbitrary series of multiplications and additions, for example: +u +v *w +x *y +z. Apply those operations on lazy1. So its value would be: ((u+v) * w +x) * y + z. lazy2 should only contain the multiplications, this would be w * y.
To update the node, first multiply by lazy2, then add lazy1.
Reason: Apply the operations to the initial value A and you get: A * w * y + ((u+v)*w +x)*y + z. It is trivial that only the multiplications affect the initial value A directly. So those can be stored in one field and the other field could contain the additions and also the multiplications have to be applied on it as the order is important here.