Imagine you're an art curator documenting a unique painting technique where artists layer colors on a canvas represented as a number line. Each artist paints a segment with their signature color, and when segments overlap, the colors mix together to create beautiful new hues!
You're given an array segments where segments[i] = [starti, endi, colori] represents a half-closed interval [starti, endi) painted with colori.
Color Mixing Rules:
- When segments overlap, their colors mix together
- Mixed colors are represented as sets:
{2, 4, 6} - For simplicity, we use the sum of colors instead of the full set
- Example: Colors 2, 4, and 6 mixing = sum of 12
Your Goal: Describe the final painting using the minimum number of non-overlapping segments, where each segment shows the mixed color sum for that region.
Example: If segments = [[1,4,5],[1,7,7]]:
• Region [1,4): Colors {5,7} mix → sum = 12
• Region [4,7): Only color {7} → sum = 7
• Result: [[1,4,12],[4,7,7]]
Input & Output
Constraints
- 1 ≤ segments.length ≤ 2 × 104
- segments[i].length == 3
- 1 ≤ starti < endi ≤ 105
- 1 ≤ colori ≤ 109
- All segments are half-closed intervals [start, end)