Technocup 2022 - Elimination Round 1
C
Omkar and Determination
Codeforces
1700
原题
← BD →
翻译中…

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 $a$ of dimensions $n \times m$ , i. e. a grid with $n$ rows and $m$ columns. You need to answer $q$ queries ($1 \leq q \leq 2 \cdot 10^5$). Each query gives two integers $x_1, x_2$ ($1 \leq x_1 \leq x_2 \leq m$) and asks whether the subgrid of $a$ consisting of the columns $x_1, x_1 + 1, \ldots, x_2 - 1, x_2$ is determinable.

翻译中…

Input

翻译中…

The first line contains two integers $n, m$ ($1 \leq n, m \leq 10^6$, $nm \leq 10^6$)  — the dimensions of the grid $a$.

翻译中…

$n$ lines follow. The $y$-th line contains $m$ characters, the $x$-th of which is 'X' if the cell on the intersection of the the $y$-th row and $x$-th column is filled and "." if it is empty.

翻译中…

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

翻译中…

$q$ lines follow. Each line contains two integers $x_1$ and $x_2$ ($1 \leq x_1 \leq x_2 \leq m$), representing a query asking whether the subgrid of $a$ containing the columns $x_1, x_1 + 1, \ldots, x_2 - 1, x_2$ is determinable.

翻译中…

Output

翻译中…

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).

翻译中…

Note

翻译中…

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

翻译中…

样例

Input #1
4 5
..XXX
...X.
...X.
...X.
5
1 3
3 3
4 5
5 5
1 5
Output #1
YES
YES
NO
YES
NO
InputCopy OutputCopy
题目信息
题号
1583C
时间限制
2 s
内存限制
256 MB
标签
数据结构
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。