#C1543. Grid Operations

    ID: 44760 Type: Default 1000ms 256MiB

Grid Operations

Grid Operations

You are given an \( n \times n \) grid with all cells initially set to 0. You need to perform a series of operations on this grid. There are three types of operations:

  • Add x y v: Add an integer \( v \) to the cell at position (x, y).
  • Set x y v: Set the cell at position (x, y) to the integer \( v \).
  • Query x1 y1 x2 y2: Compute the sum of all values in the subgrid whose top-left corner is (x1, y1) and bottom-right corner is (x2, y2), inclusive.

You must process the operations in the given order. For every Query operation, output the computed sum on a new line.

Note: All grid indices are 1-indexed. Use efficient simulation methods if necessary, though the constraints allow a straightforward approach.

inputFormat

The first line contains an integer \( n \), representing the size of the grid.

The second line contains an integer \( m \), the number of operations to perform.

Each of the following \( m \) lines describes an operation in one of the following formats:

  • Add x y v
  • Set x y v
  • Query x1 y1 x2 y2

All numbers are integers and indices are 1-indexed.

outputFormat

For each Query operation, output the corresponding sum on a separate line in the order the queries appear.

## sample
3
6
Add 1 1 5
Add 2 2 3
Query 1 1 2 2
Set 1 1 2
Query 1 1 3 3
Query 1 2 3 3
8

5 3

</p>