#P3820. 小D的地下温泉

    ID: 2757 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>并查集洛谷原创广度优先搜索,BFS连通块洛谷月赛

小D的地下温泉

Description

At the beginning, he will tell you the current state of this land, but Xiao D has some pretend operations and wants you to perform them for him:

  1. Xiao D specifies ww positions and wants to know which of these positions has the largest soaking range if he goes down to soak at that position. The soaking range is defined as the number of positions reachable from the specified position by moving in the four directions up, down, left, and right. If the queried position is soil, then the range is 00. If multiple positions tie for the maximum, output the one that appears earlier in the given order. The positions are indexed as 1,2,,w1, 2, \ldots, w.

  2. Xiao D specifies ww positions. He will use magic to toggle the terrain of these ww places in order. That is, if the original position is soil, it becomes a hot spring; if the original position is a hot spring, it becomes soil. Because Xiao D does not want the activity range to shrink too quickly, when turning a hot spring into soil he will not split a connected region.

Input Format

The first line contains two integers, N,MN, M, representing the size of the land.

The next NN lines each contain MM characters, either . (representing a hot spring) or * (representing soil).

The (N+2)(N+2)-th line contains an integer QQ, the number of operations.

In each of the next QQ lines, first read two integers optopt and ww, representing the operation type and the number of specified points. On the same line, there are also 2w2w numbers x1,y1,x2,y2,,xw,ywx_{1}, y_{1}, x_{2}, y_{2}, \ldots, x_{w}, y_{w}, which represent the ww operation positions $(x_{1}, y_{1}), (x_{2}, y_{2}), \ldots, (x_{w}, y_{w})$.

Output Format

For each operation of type 11, output the answer to the query on a new line.

5 5
.*...
.****
*....
*****
.....
3
1 2 1 1 1 3
2 1 3 1
1 2 1 1 1 3
2
1

Hint

  • For 30%30\% of the testdata, N,M100,w100N, M \le 100, \sum w \le 100.
  • For 70%70\% of the testdata, N,M1000N, M \le 1000.
  • Constraints: for 100%100\% of the testdata, 1NM,Q106,w106,w11 \le NM, Q \le 10^{6}, \sum w \le 10^{6}, w \ge 1.
  • The testdata is generated on Windows.

Translated by ChatGPT 5