Codeforces Round 371 (Div. 1)
D
Animals and Puzzle
Codeforces
2700
原题
← CE →
翻译中…

Owl Sonya gave a huge lake puzzle of size $*n* × *m*$ to hedgehog Filya as a birthday present. Friends immediately started to assemble the puzzle, but some parts of it turned out to be empty — there was no picture on them. Parts with picture on it are denoted by $1$, while empty parts are denoted by $0$. Rows of the puzzle are numbered from top to bottom with integers from $1$ to $*n*$, while columns are numbered from left to right with integers from $1$ to $*m*$.

翻译中…

Animals decided to complete the picture and play with it, as it might be even more fun! Owl and hedgehog ask each other some queries. Each query is provided by four integers $*x*_{1}$, $*y*_{1}$, $*x*_{2}$, $*y*_{2}$ which define the rectangle, where $(*x*_{1}, *y*_{1})$ stands for the coordinates of the up left cell of the rectangle, while $(*x*_{2}, *y*_{2})$ stands for the coordinates of the bottom right cell. The answer to the query is the size of the maximum square consisting of picture parts only (only parts denoted by $1$) and located fully inside the query rectangle.

翻译中…

Help Sonya and Filya answer $*t*$ queries.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 1000$) — sizes of the puzzle.

翻译中…

Each of the following $*n*$ lines contains $*m*$ integers $*a*_{*ij*}$. Each of them is equal to $1$ if the corresponding cell contains a picture and $0$ if it's empty.

翻译中…

Next line contains an integer $*t*$ ($1 ≤ *t* ≤ 1 000 000$) — the number of queries.

翻译中…

Then follow $*t*$ lines with queries' descriptions. Each of them contains four integers $*x*_{1}$, $*y*_{1}$, $*x*_{2}$, $*y*_{2}$ ($1 ≤ *x*_{1} ≤ *x*_{2} ≤ *n*$, $1 ≤ *y*_{1} ≤ *y*_{2} ≤ *m*$) — coordinates of the up left and bottom right cells of the query rectangle.

翻译中…

Output

翻译中…

Print $*t*$ lines. The $*i*$-th of them should contain the maximum size of the square consisting of $1$-s and lying fully inside the query rectangle.

翻译中…

样例

Input #1
3 4
1 1 0 1
0 1 1 0
0 1 1 0
5
1 1 2 3
2 1 3 2
3 2 3 4
1 1 3 4
1 2 3 4
Output #1
1
1
1
2
2
InputCopy OutputCopy
题目信息
题号
713D
时间限制
5 s
内存限制
512 MB
标签
二分
数据结构

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