Efficient Evaluation
Time limit2sMemory limit1024 MB
Given a queue of m tests and n moves that each remove every other test in a position range, report the smallest and largest original index removed per move.
- Level
Hard8 of 10
- Topics
- Segment tree, Simulation, Implementation
- Solved
- No attempts yet
Statement
Starting from year 20xx, the organizers of all Olympiads in informatics for high school students decided to hold their competitions online. An Organization of Online Olympiads (OOO) was created to monitor that nobody proposes an onsite competition. Such an organization needs its own contest management system. Efficient managers have already been hired, and sticks and blue tape have been bought.
To speed up solution evaluation, a new architecture was introduced. Initially, there are tests in the testing queue, in order from test 1 to test . The scheduling module performs moves in sequence. On the -th move, it picks the segment of queue positions from to inclusive and runs the solution on the tests at positions ( and have the same parity). After that, all tests the solution ran on are removed from the queue, and the remaining tests shift so that no gaps remain. For example, if the queue holds tests with initial indices 2, 3, 4, 5, 10, 12, 13, 20 and the move is , , the solution runs on the tests at positions 3, 5, and 7, which have initial indices 4, 10, and 13. Afterward the queue looks like 2, 3, 5, 12, 20.
Your goal is to implement the part of this module that, for each of the moves, finds the minimum and maximum initial index of the tests the solution ran on.
Input
The first line contains two integers and (, ), the number of moves and the number of tests initially in the queue.
Each of the following lines contains two integers and (), the parameters of the -th move. It is guaranteed that before the -th move there are at least tests in the queue, and that and have the same parity.
Output
For each of the moves, print two integers on one line: the minimum and the maximum initial index of the test that the solution ran on (and that was then removed) during that move.
Hint
Consider the first sample. 1. Initially, all tests from 1 to 10 are in the queue: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. 2. During the first move, tests 2, 4, 6, and 8 are removed. The queue becomes 1, 3, 5, 7, 9, 10. 3. During the second move, tests 1 and 5 are removed, and the queue becomes 3, 7, 9, 10.