Interval Partition Generator
Time limit1sMemory limit128 MB
The task is to decode each given lexicographic interval index on the remaining set and report the total interval count with the chosen endpoints.
- Level
Hard8 of 10
- Topics
- Segment tree, Binary search, Math
- Solved
- No attempts yet
Problem
Let . For integers , the interval is the set of consecutive integers . A partition of into intervals is a sequence of pairwise disjoint intervals whose union is exactly .
We simulate a generator that builds such a partition step by step. At every moment we keep the set of elements of that have not yet been placed into any interval; initially . In each iteration we choose one interval that is fully contained in , report it, and remove it from . We repeat until is empty.
The interval chosen in an iteration is identified by an index. Consider all intervals contained in (that is, every integer from to belongs to ). Number them from in lexicographic order by the pair (start, end). For instance, when the intervals in order are , , , , receiving indices , , , . The index of the chosen interval is given to your program through the input.
Input
The first line contains one integer ().
The remaining input lists the chosen indices, one per iteration, in order. Starting from , repeat the following while is not empty:
- Let be the number of intervals contained in the current .
- Read one integer (), the index of the chosen interval.
- Remove the interval with index from .
The given indices are exactly enough to empty : it becomes empty right after the last index is used.
Output
For each iteration, in order, print two lines:
- a line with , the number of intervals contained in at the start of that iteration;
- a line with two integers and separated by a single space, the endpoints of the chosen interval .