#K14071. Train Schedule Management
Train Schedule Management
Train Schedule Management
You are given a railway system with (n) stations. Each station maintains a schedule of trains, represented by their departure times (positive integers). You will be given (q) queries. There are two types of queries:
-
Query type 0: "0 s t" - Add a train at station (s) that departs at time (t). The departure times at each station are maintained in sorted order.
-
Query type 1: "1 s t" - Query the schedule for station (s) and report the earliest train departure time that is at or after time (t). If no such train exists, output -1.
Your task is to process all the queries and for each query of type 1, output the corresponding result.
Note: In this problem, you have to perform insertions and queries efficiently. You might use binary search for fast retrieval from the sorted list of departure times.
inputFormat
The first line contains two integers (n) and (q) representing the number of stations and the number of queries respectively. Each of the following (q) lines contains three integers: (com), (s), and (t). If (com = 0), then a train departing at time (t) is added to station (s). If (com = 1), then you must output the earliest train departure time from station (s) that is greater than or equal to (t).
outputFormat
For each query of type 1, output the result on a new line. If no train meets the condition, output -1.## sample
3 5
0 0 100
0 1 200
0 2 300
1 0 50
1 1 250
100
-1
</p>