Problem 2503 · Hard
Grow the region from the top-left cell in increasing query order, using a min heap of frontier cells.
Open the interactive visualisation