Queries on a Matrix
Submissions: 1066   Accuracy:

19.08%

  Difficulty: Hard   Marks: 8

You are given a matrix M of dimension N*N. All the cells are initially, zero. 
You are given Q queries, which contains 4 integers 
a b c d.
where (a,b) is the TOP LEFT cell and (c,d) is the Bottom Right cell of a submatrix.
Now, all the cells of This submatrix has to be incremented by one.
After all the Q queries have been performed. Your task is to print the final resulting Matrix.

NOTE: ZERO-Based Indexing is used for cells of the matrix. 
Input:
The first line contains an integer T-denoting the number of testcases.
Each test case contains N-size of the matrix and Q- Total number of queries.
Each of the next Q lines contains 4 integers- a,b,c,d as described above.
Output:
For each testcase , Print the final resulting Matrix.
Constraints:
1<=T<=100
1<=N<=100
1<=Q<=1000
0<=a,b,c,d c>=a ,d>=b 

Example:
Input:

1
6 6
4 0 5 3
0 0 3 4
1 2 1 2
1 1 2 3
0 0 3 1
1 0 2 4
Output:
2 2 1 1 1 0 
3 4 4 3 2 0 
3 4 3 3 2 0 
2 2 1 1 1 0 
1 1 1 1 0 0 
1 1 1 1 0 0

** For More Input/Output Examples Use 'Expected Output' option **

Author: iamabjain


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.