Recipe for Philosopher Stone

All submissions for this problem are available.
With the help of Sheska, Edward now has the research notes of Dr. Marcho. To prevent the secret of Philosopher stone falling into the wrong hands, Marcho has encoded the secret in the form of a list of triplets of numbers. Edward remembers that Dr. Marcho gave him a hint while he was leaving, "Sometimes you should try transmutation rectangles instead of circles, maybe they are better for making philosopher stones". Edward first thought that this was a joke, but he has understood the hint now. He interprets each triplet as the length, breadth, and color of a rectangle centered at the origin. Given below is his interpretation to decode the numbers. There are $N$ **colored** rectangles numbered from $1$ to $N$, with the $i$th rectangle having length $L_{i}$, breadth $B_{i}$ and color $C_{i}$. Each rectangle is **centered at the origin**. That is, if for any rectangle, we draw both diagonals, the diagonals shall intersect at the origin. For example, a rectangle having length 10 and breadth 2 would have its 4 corners as (5, 1), (5, 1), (5, 1) and (5, 1). The rectangles are placed one over the other. Specifically, the rectangles are placed in the order in which they appear in the input, overlapping the previous rectangles. The rectangle $i$ is partially hidden by the rectangle $j$ if $j$ > $i$. That is, only the colour of the top rectangle is visible in the overlapping region. Edward believes that the ratio of the area of each color in the final figure is pointing to some ratio of ingredients for making the philosopher stone. Can you find out how many unit squares of each colour are visible in the final figure? ### Input:  The first line contains $T$, the number of test cases. Then the test cases follow.  For each test case, the first line consists of $N$, denoting the number of rectangles and $C$ denoting the number of colours.  For each test case, $N$ lines follow, the $i$th of which contains three integers $L_{i}$, $B_{i}$ and $C_{i}$ describing length, breadth and color of the $i$th rectangle respectively. ### Output: For each test case, output a single line containing $C$ spaceseparated integers denoting the number of unit squares of each color $1$ to $C$ visible in the final figure. ### Constraints  $1 \leq T \leq 50$  $1 \leq N \leq 10^{5}$  $1 \leq C \leq 100$  $2 \leq L_{i} \leq 10^{9}$  $2 \leq B_{i} \leq 10^{9}$  $L_{i}$ and $B_{i}$ are even for all $1 \leq i \leq N$  $1 \leq C_{i} \leq C$  Sum of $N$ over all test cases doesn't exceed $10^{6}$ ### Sample Input: ``` 1 5 4 2 2 1 2 8 3 10 2 1 8 4 2 4 6 4 ``` ### Sample Output: ``` 4 16 4 24 ``` ### EXPLANATION: ![](https://codechef_shared.s3.amazonaws.com/download/HYC/External_contest_i... =500x432) In the above figure, Green represents color $1$, Blue represents color $2$, Yellow represents color $3$, and Red color represents color $4$.Author:  sachin_yadav 
Editorial  https://discuss.codechef.com/problems/LAYERS 
Tags  dcod2019, geometry, lazypropagation, sachin_yadav, sachin_yadav, segmenttree, sets 
Date Added:  20102019 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 