Animals and Puzzle

题意翻译

- 题目描述 猫头鹰 Sonya 将一个 $n\times m$ 的湖拼图给刺猬 Filya,当做他的生日礼物。小伙伴们当即去组装这个拼图,然而有一些部分是空的——在那上面没有图片。 令有图片部分的贡献为 $1$,没有的为 $0$。对这个拼图编号,行号从上到下为 $1\sim n$ ,列号从左到右为 $1\sim m$ 。 动物决定继续完成这个拼图,因为它可能更有趣。猫头鹰和刺猬会做出几组询问,每次给出四个整数 $x_1,y_1,x_2,y_2$ ,询问以 $(x_1,y_1)$ 为左上角,$(x_2,y_2)$ 为右下角的区域内,全为 $1$ 的最大正方形的边长。 - 输入格式 第一行包含两个整数 $n,m$。 接下来 $n$ 行,每行 $m$ 个为 $0$ 或 $1$ 的整数,$1$ 表示有图片,$0$ 表示没有图片。 再一行一个整数 $t$ ,表示 $t$ 组询问。 最后$t$ 行,每行四个整数分别表示 $x_1,y_1,x_2,y_2$。 - 输出格式 共 $t$ 行,每行 $1$ 个整数,表示区域内最长大的全 $1$ 正方形的边长。 感谢 @Fheiwn 提供的翻译

题目描述

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.

输入输出格式

输入格式


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<=1000000 $ ) — 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.

输出格式


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.

输入输出样例

输入样例 #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

输出样例 #1

1
1
1
2
2