Ranges
There are positions numbered from to .
For every interval , where , there is a value associated with this interval. Values can be obtained in the following ways:
- You may choose any interval and obtain its value directly. This costs one direct query.
- If, for some with , you have already obtained the values for and , then you may combine them and obtain the value for for free.
You may use the second operation any number of times. Values cannot be split: knowing the value for does not give you the values for its subintervals. There are no other ways to obtain values.
At any moment, there are required intervals. Your task is to determine the minimum number of direct queries needed to obtain the values for all required intervals.
After the initial configuration, modifications are performed. Each modification replaces one required interval with a new interval. You must output the answer for the initial configuration and after each modification.
Each configuration is considered independently. That is, for every output value, you need the minimum number of direct queries needed starting with no values already obtained.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains three integers , , and () — the number of positions, the number of required intervals, and the number of modifications.
The next lines contain two integers and (). They describe the initial required intervals.
The next lines contain three integers , , and (, ). The required interval with index is replaced by .
It is guaranteed that the sums of , , and over all test cases do not exceed each.
Output
For each test case, print integers, each on a separate line.
The first integer must be the minimum number of direct queries needed for the initial configuration. Then, after each modification, print the minimum number of direct queries needed for the current configuration.
Note
In the first test case, initially at least direct queries are needed, so the answer is .
After the first modification, the required intervals are , , and . We can query and directly, and combine them to obtain . Therefore, only direct queries are needed.
After the second modification, the required intervals are , , and . At least direct queries are needed, so the answer is .
After the third modification, the required intervals are , , and . Again, at least direct queries are needed, so the answer is .
In the second test case, the two initial required intervals are identical, so one direct query is enough and the answer is .
After each modification, at least direct queries are needed, so the answers are both .
3 5 3 3 1 2 3 5 2 4 3 1 5 1 2 2 2 4 5 3 2 2 1 3 1 3 2 1 1 1 2 3 15 8 8 15 15 13 14 10 10 8 12 8 15 15 15 15 15 14 14 1 3 3 8 10 12 4 12 14 6 13 15 6 7 11 8 10 12 3 1 3 5 11 12
3 2 3 3 1 2 2 5 6 6 7 7 8 8 8 8
Discussions & Comments
Share your approach or ask questions about this problem (0)
You must be logged in to comment or start a discussion on this problem.
Log InNo comments yet. Be the first to comment!
Actions
Open on CodeforcesAbout Platform
Problem Discussions
0Have questions or want to share your solution approach? Join the discussion.
View / write comments