Question: 2 . Paint Ball Amrita is a budding painter. One evening, she took some white drawing sheets, placed them on a table in her garden

2. Paint Ball Amrita is a budding painter. One evening, she took some white drawing sheets, placed them on a table in her garden and went to her room to get her painting brushes. It so happened that while some sheets lay on top of other sheets, none of the sheet borders intersected. Sheru, Amrita's mischievous younger brother had just returned from a paint-ball game and decided to have some fun with his sister's sheets. He used his paint pistol and fired paint balls of different colors at the sheets.Due to the force of the gun, once a paint ball hit a sheet, the ball's color spread to all of the sheets beneath it. After using all the balls, he ran away from the garden, hoping no one would notice him. When Amrita returned with the brushes, she was shocked to see the paint blots on the sheets. She wanted to know if there were any good sheets left to use or not, and therefore started counting how many colors were spread on each sheet. Can you write a program to help her? Amrita's table is represented as an endless coordinate system, with the sheets as rectangles parallel to the coordinate axes. Sheru's shots are represented as points on the coordinate system. Do keep in mind that Sheru's shots may not have touched all of the sheets, and each shot was in a different position. The colors are represented using integers as labels. Read the input from STDIN and print the output to STDOUT. Do not print arbitrary strings anywhere in the program, as these contribute to the standard output and test cases will fail. Input Format: The first line of input contains the positive integersNthe number of drawing sheets, andMthe number of paint balls. The nextNlinescontain four numbers: the coordinates of the lower-left cornerPi,Qi,and the upper right cornerRi,Siof theithpainting sheet. The nextMlinescontain three numbers: the coordinatesXj,Yjwhere Sheru's shots landed, andKj, the color label of thejthball. Output Format: The output must printNlines, one for each sheet, each containing the number of colors on theithsheet. Constraints: 1 N, M 80,0001 Pi,Qi 1091 Ri,Si 1091 Xj,Yj 1091 Kj 109 Sample Input1: 331145541096598321862993 Sample Output1: 121 Explanation1: Here, the total number of painting sheetsNis 3, andthe number of ballsMis also 3. First Sheet is spread from (1,1) to (4,5) Second Sheet is spread from (5,4) to (10,9) Third Sheet is spread from (6,5) to (9,8) Ball1 of color1 hit at (3,2) Ball2 of color2 hit at (8,6) Ball3 of color3 hit at (9,9) The below diagram depicts how the sheets were placed and where the paint balls hit. We can see that sheet 1 consists of only 1 color, sheet 2 consists of 2 different colors, and sheet 3 consists of only 1 color. Hence 1,2, and 1 are printed as output, each in a new line. Sample Input2: 2422121064107362483764411 Sample Output2: 31 Explanation2: There are 2 sheets and 4 color balls. First Sheet is spread from (2,2) to (12,10) Second Sheet is spread from (6,4) to (10,7) Color2 ball hit at (3,6) Color3 ball hit at (4,8) Color4 ball hit at (7,6) Color1 ball hit at (4,1) So, the above diagram depicts that since color1 is not touching any of the sheets, it will not be counted. Sheet 1 consists of 3 different colors, and sheet 2 consists of only 1 color.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!