#P8460. Magic Grid Massage

    ID: 21635 Type: Default 1000ms 256MiB

Magic Grid Massage

Magic Grid Massage

In the magical realm, both heroes and fairies sometimes suffer from special occupational ailments. The most common among these is known as Acute Magic Poisoning. Although its symptoms resemble a simple fever, if left untreated, it can become a chronic condition that overloads the body.

The miraculous cure is surprisingly straightforward: locate the site of magic accumulation and apply firm pressure to massage it away. In this problem, the human magic channels are represented by an n × n grid. Every grid point is a magic acupoint and can be either yin or yang. For clarity, the yang (active) acupoints are marked with black dots. Under heavy magic usage, some acupoints switch their state from yin to yang or vice‐versa, causing magic blockage. The massage is considered complete if there exists an axis‐parallel polygon (i.e. every side is parallel to the grid lines) whose vertices are all black points. Note that an axis-parallel polygon always contains at least four vertices. In fact, the simplest such polygon is a rectangle with its four corners being black.

You are given an n × n grid with m black points. Then, you will perform k operations. In each operation, a given point is toggled (if it is black, it becomes white; if it is white, it becomes black). After each operation, determine whether there exists an axis-parallel polygon with all vertices being black points. (Hint: It suffices to detect whether there exists an axis-aligned rectangle, i.e. two distinct rows and two distinct columns such that all four intersections are black.)

The formula for the grid is given in LaTeX: an n × n grid and the rectangle condition is: if there exist rows r1 and r2 (with r1 ≠ r2) and columns c1 and c2 (with c1 ≠ c2) such that $$ grid[r_1][c_1]=grid[r_1][c_2]=grid[r_2][c_1]=grid[r_2][c_2]=1, $$ then the condition is satisfied.

inputFormat

The first line contains three integers n, m, k, representing the grid dimension, the number of initial black points, and the number of operations, respectively.

The next m lines each contain two integers r and c (1-indexed), representing the coordinates of an initial black point.

The following k lines each contain two integers r and c, representing the coordinates of the point to toggle in that operation.

outputFormat

Output k lines. After each operation, output YES if there exists an axis-parallel polygon (i.e. an axis-aligned rectangle) whose vertices are all black points, and NO otherwise.

sample

3 4 3
1 1
1 2
2 1
2 2
3 3
1 1
3 3
YES

NO NO

</p>