[USACO Feb 2021 S]Comfortable Cows
题号:NC222439
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Farmer Nhoj's pasture can be regarded as a large 2D grid of square "cells" (picture a huge chessboard). Initially, the pasture is empty.
Farmer Nhoj will add N (1≤N≤105) cows to the pasture one by one. The ith cow will occupy a cell (xi,yi) that is distinct from the cells occupied by all other cows (0≤xi,yi≤1000).

A cow is said to be "comfortable" if it is horizontally or vertically adjacent to exactly three other cows. Unfortunately, cows that are too comfortable tend to lag in their milk production, so Farmer Nhoj wants to add additional cows until no cow (including the ones that he adds) is comfortable. Note that the added cows do not necessarily need to have x and y coordinates in the range 0…1000.

For each i in the range 1…N, please output the minimum number of cows Farmer Nhoj would need to add until no cows are comfortable if initially, the pasture started with only cows 1…i.

输入描述:

The first line contains a single integer N. Each of the next N lines contains two space-separated integers, indicating the (x,y) coordinates of a cow's cell.

输出描述:

The minimum number of cows Farmer Nhoj needs to add for each i in 1…N, on N separate lines.
示例1

输入

复制
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

说明

For i=4, Farmer Nhoj must add an additional cow at (2,1) to make the cow at (1,1) uncomfortable.

For i=9, the best Farmer Nhoj can do is place additional cows at (2,0), (3,0), (2,−1), and (2,3).

Problem credits: Benjamin Qi