In preparation for Christmas and a brand new year, your school is planning to host a fire drill to review the safety protocols in place.
You have decided to analyze the efficiency of the procedure by observing a particular hallway in the school. The hallway can be represented as a number line that is meters long, labelled from to . There are fire exits at locations across the hallway, and they can be accessed from classrooms that are within meters of it. It is guaranteed that there is at most one exit located at any given location . In the event that certain fire exits become too crowded, the school's front entrance (location at position ) and back door (located at position ) are deemed valid exits for any classroom in the school.
To ensure the drill goes smoothly, write a program that supports of the following queries:
1 x: What is the position of the closest reachable exit from the class at position ? If there are multiple equidistant exits, output the one with the lowest .
2 x: If the nearest exit to the class located at becomes too crowded, how many other valid exits can the class choose to take?
For this problem, you will NOT be required to pass the sample cases in order to receive points. In addition, all subtasks are disjoint, and you are NOT required to pass previous subtasks to earn points for a specific subtask.
For all queries, .
Subtask 1 [15%]
Subtask 2 [20%]
There are only type
Subtask 3 [20%]
There are only type
Subtask 4 [45%]
No additional constraints.
The first line contains two space-separated integers, and .
The next lines each contain two integers, and .
The next line contains a single integer, .
The next lines each contain a query.
For each query, output the answer on a new line.
9 3 5 2 6 1 8 0 3 1 4 1 3 2 4
5 1 2
Explanation of Sample
Query 1: The closest exit from the classroom at 4 is at location 5.
Query 2: From location 3, the front entrance and the exit at location 5 are both a distance of 2 away, but we output 1 because it has a lower value.
Query 3: The exits accessible from location 4 are at locations 1, 5 and 9. Since the closest exit at location 5 becomes too crowded, we are left with 2 exits remaining.