How to solve IOPC'12 Question GM Plants?

Looking at the submissions, it has been done by using three segment trees in x, y and z directions.
The updates are ok but the query seems unusual. Also, how to obtain the formula

r1r2r3 + r1g2g3 + g1r2g3 + g1g2r3

Problem Link

3 Likes