


Input: 'n' = 3, 'm' = 4
'queries' = [[1, 1], [1, 2], [2, 3]]
Output: [1, 1, 2]
Explanation:
Initially, the grid was:
0 0 0 0
0 0 0 0
0 0 0 0
After query (1, 1):
0 0 0 0
0 1 0 0
0 0 0 0
There is one island having land (1, 1).
After query (1, 2):
0 0 0 0
0 1 1 0
0 0 0 0
Since (1, 1) and (1, 2) share a common edge, they form one island. So there is one island having lands (1, 1) and (1, 2).
After query (2, 3):
0 0 0 0
0 1 1 0
0 0 0 1
Now there are two islands, one having lands (1, 1) and (1, 2), and another having land (2, 3).
So the number of islands after each query is [1, 1, 2].
The first line contains two integers, 'n' and 'm' denoting the number of rows and columns in the grid, respectively.
The second line contains an integer 'q' denoting the number of queries.
The next 'q' lines contain two integers each, the coordinates which are becoming land.
Print an array of size 'q', denoting the answer of each query.
You do not need to print anything; it has already been taken care of. Just implement the given function.
We can use Disjoint Set Union to keep track of connected lands efficiently.
We can make a DSU of size 'n' * 'm', and for every coordinate (i, j), we can map them to 'i' * 'm' + 'j' in the DSU.
At any query (x, y), we will check all four directions. If there is land in the adjacent coordinate, we will merge them and manage the total number of islands.