#K14336. Grid Modification and Replacement Queries

    ID: 24112 Type: Default 1000ms 256MiB

Grid Modification and Replacement Queries

Grid Modification and Replacement Queries

In this problem, you are given a grid that is initially empty. You need to process a series of queries that modify the grid. There are two types of queries:

  1. The insertion query: Ia x y c
    It attempts to insert a character c into the cell at coordinates ( (x, y) ). If the cell is already occupied (by any character), the insertion is ignored.

  2. The replacement query: Cr x1 y1 x2 y2
    For this query, consider all cells in the rectangular region given by the top-left ( (x_1, y_1) ) and bottom-right ( (x_2, y_2) ) (both inclusive). For every cell in this region that contains a character, replace its value with 'R' and count it. The query outputs the count of cells replaced.

The input starts with an integer representing the number of queries, followed by that many queries. For each Cr query, the result (number of replacements) should be printed on a new line.

Note: All coordinates are integers and the operations must be processed in the order given.

The mathematical description of the rectangular section is given by: [ { (x, y) \mid x_1 \leq x \leq x_2,; y_1 \leq y \leq y_2 } ]

inputFormat

The first line of input contains a single integer ( n ) representing the number of queries. The next ( n ) lines each contain a query. A query is one of the following formats:

  1. Insertion query: Ia x y c
    Insert character c into the grid cell at coordinates ( (x, y) ) if that cell is empty.

  2. Replacement query: Cr x1 y1 x2 y2
    For this query, replace all characters in the rectangle defined by the diagonal cells ( (x_1, y_1) ) and ( (x_2, y_2) ) with 'R' and output the count of replaced cells.

outputFormat

For each Cr query in the input, output the count of replaced cells. Each result should be printed on a separate line in the order the queries appear.## sample

5
Ia 1 1 a
Ia 2 2 b
Cr 0 0 3 3
Ia 1 1 c
Cr 1 1 2 2
2

2

</p>