CF1583C.Omkar and Determination

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The problem statement looms below, filling you with determination.

Consider a grid in which some cells are empty and some cells are filled. Call a cell in this grid exitable if, starting at that cell, you can exit the grid by moving up and left through only empty cells. This includes the cell itself, so all filled in cells are not exitable. Note that you can exit the grid from any leftmost empty cell (cell in the first column) by going left, and from any topmost empty cell (cell in the first row) by going up.

Let's call a grid determinable if, given only which cells are exitable, we can exactly determine which cells are filled in and which aren't.

You are given a grid aa of dimensions n×mn \times m , i. e. a grid with nn rows and mm columns. You need to answer qq queries (1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5). Each query gives two integers x1,x2x_1, x_2 (1≤x1≤x2≤m1 \leq x_1 \leq x_2 \leq m) and asks whether the subgrid of aa consisting of the columns x1,x1+1,…,x2−1,x2x_1, x_1 + 1, \ldots, x_2 - 1, x_2 is determinable.

题目陈述如下,令你充满决心。

考虑一个网格,其中一些格子为空,另一些格子被填满。称网格中的一个格子为可退出的(exitable),如果从该格子出发,仅通过向上或向左移动经过空格子,即可离开该网格。注意:该格子自身也包含在路径中,因此所有被填满的格子均不是可退出的。此外,你可以从任意最左侧的空格子(即第一列中的空格子)向左移出网格,也可以从任意最上方的空格子(即第一行中的空格子)向上移出网格。

若仅凭哪些格子是可退出的这一信息,便能精确确定每个格子是否被填满,则称该网格为可判定的(determinable)。

给定一个 n×mn \times m 维度的网格 aa(即具有 nn 行、mm 列的网格)。你需要回答 qq 个查询(1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5)。每个查询给出两个整数 x1,x2x_1, x_2(1≤x1≤x2≤m1 \leq x_1 \leq x_2 \leq m),询问由列 x1,x1+1,…,x2−1,x2x_1, x_1 + 1, \ldots, x_2 - 1, x_2 构成的 aa 的子网格是否为可判定的。

输入格式

The first line contains two integers n,mn, m (1≤n,m≤1061 \leq n, m \leq 10^6, nm≤106nm \leq 10^6) — the dimensions of the grid aa.

nn lines follow. The yy-th line contains mm characters, the xx-th of which is 'X' if the cell on the intersection of the the yy-th row and xx-th column is filled and "." if it is empty.

The next line contains a single integer qq (1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5) — the number of queries.

qq lines follow. Each line contains two integers x1x_1 and x2x_2 (1≤x1≤x2≤m1 \leq x_1 \leq x_2 \leq m), representing a query asking whether the subgrid of aa containing the columns x1,x1+1,…,x2−1,x2x_1, x_1 + 1, \ldots, x_2 - 1, x_2 is determinable.

第一行包含两个整数 n,mn, m(1≤n,m≤1061 \leq n, m \leq 10^6,且 nm≤106nm \leq 10^6)——表示网格 aa 的维度。

接下来是 nn 行。第 yy 行包含 mm 个字符,其中第 xx 个字符为 'X' 表示第 yy 行与第 xx 列交叉处的格子已被填充,为 '.' 表示该格子为空。

下一行包含一个整数 qq(1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5)——表示查询的数量。

接下来是 qq 行,每行包含两个整数 x1x_1 和 x2x_2(1≤x1≤x2≤m1 \leq x_1 \leq x_2 \leq m),表示一个查询:询问网格 aa 中由第 x1,x1+1,…,x2−1,x2x_1, x_1 + 1, \ldots, x_2 - 1, x_2 列构成的子网格是否可判定(determinable)。

输出格式

For each query, output one line containing "YES" if the subgrid specified by the query is determinable and "NO" otherwise. The output is case insensitive (so "yEs" and "No" will also be accepted).

对于每个查询,如果查询指定的子网格是可确定的,则输出一行“YES”;否则输出“NO”。输出不区分大小写(因此“yEs”和“No”也会被接受)。

输入输出样例

  • 输入#1

    4 5
    ..XXX
    ...X.
    ...X.
    ...X.
    5
    1 3
    3 3
    4 5
    5 5
    1 5

    输出#1

    YES
    YES
    NO
    YES
    NO

说明/提示

For each query of the example, the corresponding subgrid is displayed twice below: first in its input format, then with each cell marked as "E" if it is exitable and "N" otherwise.

For the first query:

..X EEN
... EEE
... EEE
... EEE

For the second query:

X N
. E
. E
. E

Note that you can exit the grid by going left from any leftmost cell (or up from any topmost cell); you do not need to reach the top left corner cell to exit the grid.

For the third query:

XX NN
X. NN
X. NN
X. NN

This subgrid cannot be determined only from whether each cell is exitable, because the below grid produces the above "exitability grid" as well:

XX
XX
XX
XX

For the fourth query:

X N
. E
. E
. E

For the fifth query:

..XXX EENNN
...X. EEENN
...X. EEENN
...X. EEENN

This query is simply the entire grid. It cannot be determined only from whether each cell is exitable because the below grid produces the above "exitability grid" as well:

..XXX
...XX
...XX
...XX

对于示例中的每个查询,对应的子网格在下方显示两次:第一次以输入格式呈现,第二次则在每个单元格中标注为“E”(表示可逃逸)或“N”(表示不可逃逸)。

第一个查询:

..X EEN
... EEE
... EEE
... EEE

第二个查询:

X N
. E
. E
. E

注意:你可以通过向左移动从任意最左侧单元格(或向上移动从任意最上方单元格)逃逸出网格;你无需到达左上角单元格即可逃逸出网格。

第三个查询:

XX NN
X. NN
X. NN
X. NN

该子网格无法仅根据每个单元格是否可逃逸来唯一确定,因为下面的网格也会产生上述相同的“可逃逸性网格”:

XX
XX
XX
XX

第四个查询:

X N
. E
. E
. E

第五个查询:

..XXX EENNN
...X. EEENN
...X. EEENN
...X. EEENN

该查询即为整个网格。它无法仅根据每个单元格是否可逃逸来唯一确定,因为下面的网格也会产生上述相同的“可逃逸性网格”:

..XXX
...XX
...XX
...XX

输入解题思路,AI测评打分。不知道怎么写?

首页