The only difference between the two versions of the problem is whether overlaps are considered at all points or only at integer points.
The legendary Simurgh, a mythical bird, is responsible for keeping watch over vast lands, and for this purpose, she has enlisted $$$n$$$ vigilant warriors. Each warrior is alert during a specific time segment $$$[l_i, r_i]$$$, where $$$l_i$$$ is the start time (included) and $$$r_i$$$ is the end time (included), both positive integers.
One of Simurgh's trusted advisors, Zal, is concerned that if multiple warriors are stationed at the same time and all wear the same color, the distinction between them might be lost, causing confusion in the watch. To prevent this, whenever multiple warriors are on guard at the same integer moment, there must be at least one color which is worn by exactly one warrior.
So the task is to determine the minimum number of colors required and assign a color $$$c_i$$$ to each warrior's segment $$$[l_i, r_i]$$$ such that, for every (integer) time $$$t$$$ contained in at least one segment, there exists one color which belongs to exactly one segment containing $$$t$$$.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
For each test case:
The sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case:
351 42 83 75 106 951 52 63 74 76 754 98 172 1512 196 13
2 1 2 2 1 2 2 1 2 2 2 1 3 1 1 2 3 1
We can represent each warrior's watch segment as an interval on the X-axis;
In test case 1, the intervals can be colored as shown below (intervals are colored with the selected color; areas are colored if this color occurs exactly once at this point in time):
In test case 2, the intervals can be colored as shown below:
In test case 3, the intervals can be colored as shown below:
Name |
---|