#K58682. Homogeneous Subgrid Queries

    ID: 30697 Type: Default 1000ms 256MiB

Homogeneous Subgrid Queries

Homogeneous Subgrid Queries

You are given a grid of n rows and m columns. Each row of the grid is a string of exactly m characters.

Then, you are given q queries. Each query consists of four integers \(a, b, c, d\) which denote the top‐left and bottom‐right coordinates of a subgrid. The coordinates are 1-indexed. For each query, determine whether the subgrid formed by the rows a to c and columns b to d is homogeneous, i.e. every cell in the subgrid contains the same character.

For example, consider the grid:

aaaa
bbbb
cccc
and the queries:
1 1 1 4
2 1 3 4
The answer for the first query is "YES" because the subgrid (first row) contains all 'a's and the answer for the second query is "NO" because the subgrid contains both 'b's and 'c's.

Note: When referring to coordinates, convert the given 1-indexed values to 0-indexed values for internal representation if necessary. Also, any formulas should be formatted in LaTeX. For example, the subgrid spans rows \(a\) to \(c\) and columns \(b\) to \(d\), which can be written as \(\{(i,j) \mid a \le i \le c,\; b \le j \le d\}\).

inputFormat

The input is given from stdin in the following format:

n m q
row1
row2
...\nrow_n
query1_a query1_b query1_c query1_d
query2_a query2_b query2_c query2_d
...\nquery_q_a query_q_b query_q_c query_q_d

Where \(n\) and \(m\) are integers representing the number of rows and columns in the grid respectively, and \(q\) is the number of queries. Each of the next \(n\) lines contains a string of length \(m\) representing a row of the grid. Each query is represented by four integers \(a, b, c, d\) (1-indexed).

outputFormat

For each query, output a line with either YES if the specified subgrid is homogeneous or NO otherwise. The output should be written to stdout.

## sample
3 4 2
aaaa
bbbb
cccc
1 1 1 4
2 1 3 4
YES

NO

</p>