#K86017. Tracking Trains on the Track
Tracking Trains on the Track
Tracking Trains on the Track
You are given a list of events representing train arrivals and departures at a track. Each event is described by three values: a timestamp, an event type (which can be either arrival or departure), and the train's unique ID.
Your task is to process these events in the order they are given, updating the state of the track accordingly. When a train arrives, it is added to the track. When a train departs, it is removed from the track if it exists there.
After processing all events, output the list of train IDs that remain on the track in increasing order. If no trains remain, output an empty line.
The event processing can be mathematically modeled as follows:
\(\text{Track state update is defined by:}\)
\(\text{If event type = arrival, then } T \leftarrow T \cup \{trainId\}\)
\(\text{If event type = departure, then } T \leftarrow T \setminus \{trainId\}\)
\(\text{After processing all events, output } sorted(T).\)
inputFormat
The input is given via standard input (stdin). The first line contains an integer n, representing the number of events. Each of the following n lines contains an event described by three space-separated fields: time
(an integer), event_type
(a string that is either "arrival" or "departure"), and train_id
(an integer).
outputFormat
Print the train IDs that remain on the track in increasing order, separated by a space, to standard output (stdout). If there are no trains on the track, output an empty line.## sample
5
1 arrival 101
2 arrival 102
3 departure 101
4 arrival 103
5 departure 102
103