#C9520. Distinct Widget Count
Distinct Widget Count
Distinct Widget Count
You are given T test cases. In each test case, there are M client orders. Each order is specified as a pair of integers \(L\) and \(R\) representing a contiguous range of widget IDs ordered by that client.
Your task is to determine the total number of distinct widget IDs ordered in each test case. In other words, for each test case, you should compute the size of the union of all intervals \([L, R]\) provided.
Note: Use efficient methods to merge overlapping intervals if necessary.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer \(T\), the number of test cases.
- For each test case, the first line contains an integer \(M\), the number of orders.
- This is followed by \(M\) lines, each with two space-separated integers \(L\) and \(R\) indicating an order for all widget IDs from \(L\) to \(R\) (inclusive).
outputFormat
For each test case, output a single line with one integer: the count of distinct widget IDs ordered in that test case. The output should be written to stdout.
## sample2
3
1 5
4 8
10 12
4
1 1
2 2
3 3
1 3
11
3
</p>