#C5111. Grid Game Query Processing

    ID: 48725 Type: Default 1000ms 256MiB

Grid Game Query Processing

Grid Game Query Processing

You are given an N x N grid initialized with zeros. You will receive a series of queries to either update an element or compute the sum of a subgrid. There are two types of queries:

  • SET i j v: Set the element at row i and column j to value v.
  • SUM x1 y1 x2 y2: Compute the sum of all elements in the subgrid with the top-left corner at (x1, y1) and bottom-right corner at (x2, y2).

The queries are processed in the order they are given. Note that if an element is updated more than once, only the most recent value is used in subsequent sum queries.

For a query of type SUM, output the result on a new line.

For example, if the grid size is 4 and the queries are:

SET 1 2 5
SUM 1 1 3 3

Then the output will be:

5

inputFormat

The first line of input contains two integers, N and Q, where N is the size of the grid (N x N) and Q is the number of queries.

Each of the following Q lines contains a query in one of the following formats:

  • SET i j v
  • SUM x1 y1 x2 y2

All indices use 0-based numbering.

outputFormat

For each SUM query, output the computed sum on a separate line in the order they appear.

## sample
4 2
SET 1 2 5
SUM 1 1 3 3
5

</p>