#P4259. [Code+#3] 寻找车位

[Code+#3] 寻找车位

Description

access_globe has a huge parking lot with nn rows and mm spaces per row. For aesthetics, when building this parking lot, access_globe stipulated that it must be strip-shaped, i.e., nmn\ge m. Each parking space is a square area.

Recently, access_globe has been distressed about not being able to draw "Missing Poster", so he asks you to help maintain this parking lot. You need to support two types of events:

  • A car parks in a certain space, or a car leaves a certain space.
  • Query, within a rectangular region, the largest square region consisting only of empty spaces.

If you can help access_globe solve this efficiently, access_globe will reward you well.

Input Format

The first line contains three positive integers nn, mm, and qq, denoting the size of the parking lot and the number of events.

The next nn lines each contain mm numbers, either 00 or 11. If the number at row ii, column jj is 11, then the space at row ii, column jj is empty; otherwise, that space is non-empty.

The next qq lines each describe an event in one of the following two forms:

  • 00 xx yy: The occupancy status of the space at row xx, column yy toggles. That is, if this space was empty before this event, it becomes non-empty after the event; otherwise, it becomes empty. It is guaranteed that 1xn1\le x\le n, 1ym1\le y\le m.
  • 11 ll ss rr tt: Query the side length of the largest all-empty square region within the rectangle with opposite corners (l,s)(l, s) and (r,t)(r, t). It is guaranteed that 1lrn1\le l\le r\le n, 1stm1\le s\le t\le m.

Output Format

For each query, output one integer on its own line, representing the side length of the largest all-empty square for that query.

5 4 10
1 1 1 0
1 1 1 1
1 1 0 1
1 0 1 0
1 1 0 0
1 1 1 5 4
1 3 1 3 1
1 3 3 3 3
1 2 3 5 3
0 2 2
1 1 4 2 4
1 1 3 3 3
0 5 1
1 2 3 2 4
1 1 2 2 4

2
1
0
1
1
1
1
1

Hint

Subtask ID Extra constraints on n,mn, m Extra constraints on qq Update operations Whether guaranteed that s=1,t=ms=1, t=m
11 n,m500n,m \le 500 q500q \le 500 Present No
22 m10m \le 10 None Guaranteed absent Yes
33 ^ ^ Present ^
44 n400000n \le 400000 Guaranteed absent
55 ^ Present
66 m10m \le 10 Guaranteed absent No
77 ^ Present ^
88 n400000n \le 400000 Guaranteed absent
99 ^ Present
1010 None ^

All subtasks are evenly weighted.

For all testdata, it is guaranteed that n×m4×106n\times m\le 4\times 10^6, q2000q\le 2000.

Credit: https://www.luogu.org/discuss/show?postid=35727

Translated by ChatGPT 5