A terrain editor lets a designer raise land one cell at a time on an ocean map. After each click, the status bar shows how many islands there are and how big the largest one is. Islands are groups of land cells connected up, down, left or right, not diagonally.
The map has rows × cols cells and starts as all water. additions is a list of [row, col] cells turned into land, in order.
islandCounts(rows, cols, additions) returns an array with one number per addition: the number of islands right after it.
largestIslands(rows, cols, additions) returns an array with one number per addition: the number of cells in the largest island right after it.
Rules:
Turning a cell that is already land into land again changes nothing; it still gets an entry in the result.
An empty additions list returns [].
If rows or cols is not a positive safe integer, or an addition lies outside the map, throw a RangeError. If additions is not an array of [row, col] integer pairs, throw a TypeError.
rows and cols can each be up to 1,000,000, so do not allocate the whole map. There can be 100,000 additions; recounting the islands after each one is far too slow.