Got AC, silly mistake =(
My approach works as follows:
- For every operation, get all the sub-rectangles affected and save all these operations (function add)
- Since M < 50, use grid compression
- Count the number of 0's that there were initially in a sub-rectangle (function count), if the state of the bulbs changed add the number of 0's else add the number of 1's.