#P6645. [CCO 2020] Interval Collection
[CCO 2020] Interval Collection
Description
Altina is collecting intervals. A pair of positive integers with is an interval, and we call the length of such an interval .
We say that interval contains interval if and only if and . In particular, every interval contains itself.
For a non-empty set , define its maximum common sub-interval as the longest interval that is contained in every interval in . If no such interval exists, it is undefined.
For a non-empty set , define its minimum common super-interval as the shortest interval that contains every interval in . Note that such an interval always exists.
Initially, there are no intervals in Altina’s collection. Then events will happen, which change Altina’s collection.
- Altina adds an interval to her collection. If already exists in the collection, it should be counted as a different interval.
- Altina removes an interval that already exists in the collection. If there are multiple identical ones, remove exactly one.
After each event, Altina chooses a non-empty subset of her collection, satisfying the following rules:
- Among all choices, she will choose one where the maximum common sub-interval is undefined. If no such choice exists, she will choose one where the length of the maximum common sub-interval is as small as possible.
- Among all sets that satisfy the rule above, she will choose one where the length of the minimum common super-interval is as small as possible.
After each event, output the length of the minimum common super-interval of the set that Altina will choose.
Input Format
The first line contains a positive integer , the number of events.
The next lines each describe an event in one of the following formats:
- : add an interval to Altina’s collection.
- : remove an interval from Altina’s collection. It is guaranteed that this interval exists in her collection, and that after removal her collection is non-empty.
Output Format
Output lines. Each line contains one positive integer, the length of the minimum common super-interval of the set that Altina will choose after that event.
5
A 1 5
A 2 7
A 4 6
A 6 8
R 4 6
4
6
5
4
7
Hint
Sample Explanation
Add . Choosing is optimal, so the answer is .
Add . Choosing is optimal, so the answer is .
Add . Choosing is optimal, so the answer is .
Add . Choosing is optimal, so the answer is .
Remove . Choosing is optimal, so the answer is .
Subtasks
This problem uses bundled testdata.
- Subtask 1 ( points): .
- Subtask 2 ( points): .
- Subtask 3 ( points): .
- Subtask 4 ( points): For any two intervals and , it is guaranteed that or .
- Subtask 5 ( points): No special restrictions.
For of the data, it is guaranteed that and .
Notes
This problem is translated from Canadian Computing Olympiad 2020 Day 2 T2 Interval Collection.
Translated by ChatGPT 5
京公网安备 11011102002149号