#P9944. Comfortable Cows
Comfortable Cows
Comfortable Cows
Farmer John's field can be viewed as a huge two-dimensional grid of square cells. Initially, the field is empty. Farmer John will add $N$ cows (with $1\le N\le 10^5$) one-by-one. The i-th cow occupies the cell at $(x_i, y_i)$ (with $0\le x_i,y_i\le 1000$), and no two cows occupy the same cell.
A cow is defined as comfortable if it has exactly three neighbors in the four cardinal directions (up, down, left, right). After each cow is added, output the total number of comfortable cows currently on the field.
Note: Neighbors refer only to adjacent cells in horizontal or vertical directions.
The mathematical conditions in this problem are given in \(\LaTeX\):
- \(1\le N\le 10^5\)
- \(0\le x_i, y_i\le 1000\)
inputFormat
The first line contains a single integer $N$, the number of cows.
Each of the following $N$ lines contains two integers $x_i$ and $y_i$, representing the coordinates of the cow added to the field.
It is guaranteed that all positions are distinct.
outputFormat
Output $N$ lines. The i-th line should contain a single integer representing the number of comfortable cows after the first i cows have been added.
sample
1
0 0
0
</p>