CF232E.Quick Tortoise

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

John Doe has a field, which is a rectangular table of size n×mn×m . We assume that the field rows are numbered from 1 to nn from top to bottom, and the field columns are numbered from 1 to mm from left to right. Then the cell of the field at the intersection of the xx -th row and the yy -th column has coordinates ( xx ; yy ).

We know that some cells of John's field are painted white, and some are painted black. Also, John has a tortoise, which can move along the white cells of the field. The tortoise can get from a white cell with coordinates ( xx ; yy ) into cell ( x+1x+1 ; yy ) or ( xx ; y+1y+1 ), if the corresponding cell is painted white. In other words, the turtle can move only along the white cells of the field to the right or down. The turtle can not go out of the bounds of the field.

In addition, John has qq queries, each of them is characterized by four numbers x1,y1,x2,y2x_{1},y_{1},x_{2},y_{2} ( x1<=x2x_{1}<=x_{2} , y1<=y2y_{1}<=y_{2} ). For each query John wants to know whether the tortoise can start from the point with coordinates ( x1x_{1} ; y1y_{1} ), and reach the point with coordinates ( x2x_{2} ; y2y_{2} ), moving only along the white squares of the field.

输入格式

The first line contains two space-separated integers nn and mm ( 1<=n,m<=5001<=n,m<=500 ) — the field sizes.

Each of the next nn lines contains mm characters "#" and ".": the jj -th character of the ii -th line equals "#", if the cell ( ii ; jj ) is painted black and ".", if it is painted white.

The next line contains integer qq ( 1<=q<=6105)1<=q<=6·10^{5}) — the number of queries. Next qq lines contain four space-separated integers x1x_{1} , y1y_{1} , x2x_{2} and y2y_{2} ( 1<=x1<=x2<=n1<=x_{1}<=x_{2}<=n , 1<=y1<=y2<=m1<=y_{1}<=y_{2}<=m ) — the coordinates of the starting and the finishing cells. It is guaranteed that cells ( x1x_{1} ; y1y_{1} ) and ( x2x_{2} ; y2y_{2} ) are white.

输出格式

For each of qq queries print on a single line "Yes", if there is a way from cell ( x1x_{1} ; y1y_{1} ) to cell ( x2x_{2} ; y2y_{2} ), that meets the requirements, and "No" otherwise. Print the answers to the queries in the order, in which the queries are given in the input.

输入输出样例

  • 输入#1

    3 3
    ...
    .##
    .#.
    5
    1 1 3 3
    1 1 1 3
    1 1 3 1
    1 1 1 2
    1 1 2 1
    

    输出#1

    No
    Yes
    Yes
    Yes
    Yes
    
  • 输入#2

    5 5
    .....
    .###.
    .....
    .###.
    .....
    5
    1 1 5 5
    1 1 1 5
    1 1 3 4
    2 1 2 5
    1 1 2 5
    

    输出#2

    Yes
    Yes
    Yes
    No
    Yes
    
首页