#P3684. [CERC2016] 机棚障碍 Hangar Hurdles

    ID: 1212 远端评测题 4000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016并查集强连通分量,缩点树链剖分,树剖

[CERC2016] 机棚障碍 Hangar Hurdles

Description

You are evaluating construction plans for a giant airplane hangar. The hangar floor can be represented as an n×nn \times n grid, where each cell is either empty or contains an obstacle. Rows are numbered from 11 to nn from top to bottom, and columns are numbered from 11 to nn from left to right.

It is important that large containers for storing airplane parts can move freely on the floor. Each container can be seen as an axis-aligned square centered at some cell. For an odd integer kk, a container of size kk is a square covering kk rows and kk columns. The coordinate of a container is the coordinate of its center cell. A container can move up, down, left, or right, but it cannot touch obstacles and cannot move outside the hangar boundary.

Given qq pairs of cells AkA_k and BkB_k, for each pair, find the maximum size (also an odd integer) of a container that can move from AkA_k to BkB_k.

Input Format

The first line contains a positive integer nn (2n10002 \le n \le 1000), the size of the hangar.

The next nn lines each contain nn characters describing the hangar, where . denotes an empty cell and # denotes an obstacle.

The next line contains a positive integer qq (1q3000001 \le q \le 300000), the number of queries.

Each of the next qq lines contains four positive integers Ax,Ay,Bx,ByA_x, A_y, B_x, B_y (1Ax,Ay,Bx,Byn1 \le A_x, A_y, B_x, B_y \le n), the coordinates of AA and BB.

It is guaranteed that AA and BB are distinct empty cells.

Output Format

Output qq lines, each with one integer. For each query, output the maximum size. If no solution exists, output 00.

7
.....#.
...#.#.
....#..
....###
....#..
#......
.......
5
2 5 5 2
2 5 3 6
2 2 6 3
2 2 6 6
1 1 7 7
1
0
3
1
1

Hint

Translated by ChatGPT 5