


Initially, let ‘MAT’ be :
0 0 0
0 0 0
0 0 0
Let the ‘BULB’ array be: [[0, 0]]
‘MAT’ will be changed to :
‘1’ 1 1
1 1 0
1 0 1 where (1 represents the cell is illuminated and ‘1’ represents the cell is illuminated and the bulb is turned ON).
Let ‘QUERY’ array be : [[0, 1]]
As the cell [0, 1] is illuminated, we will print 1 and then turn OFF the bulb at that position and adjacent to it.
‘MAT’ will be changed to :
0 0 0
0 0 0
0 0 0
The first line of input contains an integer ‘T’, denoting the number of test cases.
The first line of each test case contains two space-separated integers, ‘N’, ‘M’, and ‘Q’, representing the size of the matrix, the size of the ‘BULB’ array, and the size of the ‘QUERY’ array.
The next ‘M’ lines of each test case contain two space-separated integers representing the ‘BULB’ array elements.
The next ‘Q’ lines of each test case contain two space-separated integers representing the ‘QUERY’ array elements.
For each test case, print the result of queries in 0 and 1, where 0 represents the cell is not illuminated, and 1 represents the cell is illuminated.
Print output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= M, N, Q <= 2*10^4
0 <= BULB[i][0], BULB[i][1], QUERY[i][0], QUERY[i][1] < N
Time Limit: 1 sec
The basic idea is to simply check every row, column, and diagonal from which a cell can be illuminated for each query. For each cell, there can be 1 row, 1 column, and four diagonals from which it can be illuminated. So we simply check whether a bulb is ON or not in these. We use a set to store the positions of the bulbs that are already ON.
CHECK(‘N’, ‘S’, ‘R’, ‘C’) (where ‘N’ is the size of the matrix, ‘S’ is the set that consists of positions where the bulb is ON, ‘R’ and ‘C’ is the position of the current query).
The basic idea is to store the count of rows and columns from which a cell can be illuminated. We store these values for each cell. We also store the count of diagonals from which a cell can be illuminated. And for each query, we check whether any of the rows, columns or diagonal for a cell have a count greater than 1, if it is, we print 1, else 0. After performing each query, we subtract the row, column, and diagonal count for that cell and its adjacent cells. We also use a set to store the bulbs, which are turned ON.