Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Imagine each row as a separate array. Instead of updating the whole submatrix together, we can use prefix sum to update each row separately.
For each query, iterate over the rows i in the range [row1, row2] and add 1 to prefix sum S[i][col1], and subtract 1 from S[i][col2 + 1].
After doing this operation for all the queries, update each row separately with S[i][j] = S[i][j] + S[i][j - 1].