Overtaking
Time limit2sMemory limit1024 MB
Buses on a one-way road can overtake only at sorting stations. For each query departure time Y of a reserve bus, find when it reaches the hotel.
- Level
Hard9 of 10
- Topics
- Segment tree, Binary search, Simulation, Sorting
- Solved
- No attempts yet
Statement
A one-lane, one-way road runs from Budapest Airport to Hotel Forrás. The road is kilometres long.
During the IOI 2023 event, transfer buses travel on this road. The buses are numbered from to . Bus () is scheduled to leave the airport at the -th second of the event, and it can travel 1 kilometre in seconds. Bus is a reserve bus that can travel 1 kilometre in seconds. The time when the reserve bus leaves the airport has not been decided yet.
Overtaking is generally not allowed on the road. Instead, buses may overtake each other at sorting stations. There are sorting stations (), numbered from to , at different positions on the road. Sorting station is kilometres from the airport. The stations are in increasing order of distance, so for each . The first station is the airport and the last station is the hotel, so and .
A bus travels at its maximum speed unless it catches up to a slower bus ahead of it. In that case, the two buses bunch together and travel at the speed of the slower bus until they reach the next sorting station. There, the faster bus overtakes the slower one.
Formally, let be the time in seconds when bus arrives at sorting station , for each and . Let for , and let . For each , define the expected time of arrival as the time bus would reach station if it travelled at full speed from station :
Bus arrives at station at the maximum of and for every bus () with .
You must answer queries. Each query gives the departure time of the reserve bus. Find the time at which the reserve bus arrives at the hotel.
Constraints
, , for each with , for each with , , , , , .