Table Range Sum with Updates
Time limit1sMemory limit256 MB
Apply point updates on an N by N table and answer each rectangle sum query in order.
- Level
Medium4 of 10
- Topics
- Segment tree
- Solved
- No attempts yet
Problem
An table is filled with natural numbers. The cell in row and column is written as . The sum from to is the sum of the numbers in every cell with and .
Two kinds of operations arrive mixed together: one replaces the number in a single cell, the other asks for the sum of a rectangle. Consider with the table below.
The sum from to is . If the number in is then replaced with , the sum over the same rectangle becomes .
Given the initial table and the operations in order, write a program that prints the value for each sum operation.
Input
The first line contains the table size and the number of operations . (, )
Each of the next lines contains one row of the table, starting from row 1. Each line holds numbers separated by spaces, and every number in the table is a natural number at most .
Each of the following lines contains one operation, given either as four integers , , , or as five integers , , , , . If , replace the number in with . If , compute the sum from to . (, , , , )
Output
For each operation with , print the computed sum on its own line, in the order the operations are given.