rows
and cols
, to keep track of the rows and columns that have been updated.res
to store the result, the sum of the matrix after all queries.rows
and update res
by adding vali * n
and subtracting vali * len(cols)
.cols
and update res
by adding vali * n
and subtracting vali * len(rows)
.res
.