#P7411. [USACO21FEB] Comfortable Cows S

[USACO21FEB] Comfortable Cows S

Description

Farmer Nhoj’s pasture can be viewed as a huge two-dimensional grid made of square cells (imagine a huge chessboard). Initially, the pasture is empty.

Farmer Nhoj will add NN cows (1N1051\le N\le 10^5) to the pasture one by one. The ii-th cow will occupy the cell (xi,yi)(x_i,y_i), which is different from all cells already occupied by other cows (0xi,yi10000\le x_i,y_i\le 1000).

A cow is called “comfortable” if it has exactly three other cows adjacent to it horizontally or vertically. However, cows that are too comfortable often produce less milk, so Farmer Nhoj wants to add some extra cows until no cow (including the newly added cows) is comfortable. Note that the xx and yy coordinates of the added cows do not necessarily need to be within the range 010000 \ldots 1000.

For each ii in 1N1 \ldots N, output the minimum number of cows Farmer Nhoj needs to add so that there are no comfortable cows, given that the pasture initially contains cows 1i1 \ldots i.

Input Format

The first line contains an integer NN. The next NN lines each contain two space-separated integers, giving the coordinates (x,y)(x,y) of a cow.

Output Format

Output NN lines. For each ii in 1N1 \ldots N, output one line containing the number of cows Farmer Nhoj needs to add.

9
0 1
1 0
1 1
1 2
2 1
2 2
3 1
3 2
4 1
0
0
0
1
0
0
1
2
4

Hint

For i=4i=4, Farmer Nhoj needs to add a cow at (2,1)(2,1) so that the cow at (1,1)(1,1) is no longer comfortable.

For i=9i=9, Farmer Nhoj’s best plan is to add cows at (2,0)(2,0), (3,0)(3,0), (2,1)(2,-1), and (2,3)(2,3).

Problem by: Benjamin Qi.

Translated by ChatGPT 5