Codeforces Round #248 (Div. 1) B. Nanamis Digital Board(DP+

B. Nanami’s Digital Board

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Nanami is an expert at playing games. This day, Nanami’s good friend Hajime invited her to watch a game of baseball. Unwilling as she was, she followed him to the stadium. But Nanami had no interest in the game, so she looked around to see if there was something that might interest her. That’s when she saw the digital board at one end of the stadium.

The digital board isnpixels in height andmpixels in width, every pixel is either light or dark. The pixels are described by its coordinate. Thej-th pixel of thei-th line is pixel(i,j). The board displays messages by switching a combination of pixels to light, and the rest to dark. Nanami notices that the state of the pixels on the board changes from time to time. At certain times, certain pixels on the board may switch from light to dark, or from dark to light.

Nanami wonders, what is the area of the biggest light block such that a specific pixel is on its side. A light block is a sub-rectangle of the board, in which all pixels are light. Pixel(i,j)belongs to a side of sub-rectangle with(x1,y1)and(x2,y2)as its upper-left and lower-right vertex if and only if it satisfies the logical condition:

((i=x1ori=x2) and (y1≤j≤y2)) or ((j=y1orj=y2) and (x1≤i≤x2)).

Nanami has all the history of changing pixels, also she has some questions of the described type, can you answer them?

Input

The first line contains three space-separated integersn,mandq(1≤n,m,q≤1000)— the height and width of the digital board, and the number of operations.

Then follownlines, each line containingmspace-separated integers. Thej-th integer of thei-th line isai,j— the initial state of pixel(i,j).

Ifai,j=0, pixel(i,j)is initially dark.Ifai,j=1, pixel(i,j)is initially light.

Then followqlines, each line containing three space-separated integersop,x, andy(1≤op≤2;1≤x≤n;1≤y≤m), describing an operation.

Ifop=1, the pixel at(x,y)changes its state (from light to dark or from dark to light).Ifop=2, Nanami queries the biggest light block with pixel(x,y)on its side.

Output

For each query, print a single line containing one integer — the answer to Nanami’s query.

Sample test(s)

input

3 4 50 1 1 01 0 0 10 1 1 02 2 22 1 21 2 21 2 32 2 2

output

026

input

3 3 41 1 11 1 11 1 12 2 21 2 22 1 12 2 1

output

633

Note

Consider the first sample.

The first query specifies pixel(2,2), which is dark itself, so there are no valid light blocks, thus the answer is 0.

The second query specifies pixel(1,2). The biggest light block is the block with(1,2)as its upper-left vertex and(1,3)as its lower-right vertex.

The last query specifies pixel(2,2), which became light in the third operation. The biggest light block is the block with(1,2)as its upper-left vertex and(3,3)as its lower-right vertex.

题意:

已知一01矩阵,有两个操作。

1.使(x,y)的值反转(0变成1,1变成0)

2.找出一个最大的1矩阵且(x,y)点必须在这个矩阵边界上

思路:这种最大子矩阵的显然要用经典的dp,维护每个点向上向下向左向右连续的1的最大距离

然后可以用往常的最大子矩阵的思路用单调栈dp出以每个高度往左往右延伸的最远距离,然后只要跨过(x,y)点就符合

但这种用单调栈的方法很经典但是不方便

也可以用双指针,比如从(x,y)有左右移动的两个双指针,每次根据max(h[l-1],h[r+1])决定向左还是向右移动,然后一直维护目前为止h(igh)数组的最小值,,更新ans=max(ans,curminh*len)即可,这种双指针的移动规则一定能遍历最优解

法一(单调栈):

获致幸福的不二法门是珍视你所拥有的遗忘你所没有的。

Codeforces Round #248 (Div. 1) B. Nanamis Digital Board(DP+

相关文章:

你感兴趣的文章:

标签云: