DMPG '17 G4 - Timeline
View as PDFHarold is, like the rest of his coworkers, working hard to ensure all records are "accurate". To do this they must change some labels here and there, but more importantly, change the time that certain events occurred… in the database.
Unfortunately for you, many students are looking up "information" for their projects at the same time, and all the queries are grouped together. You wouldn't want to keep them waiting.
The timeline begins with  events, each occurring at a distinct time 
 and having a label 
. Initially the search filter allows all events to pass. There will be 
 queries, which will be one of the following:
T a b- find the event which occurred at timeand change it so it occurred at time
.
L a b- find the event which occurred at timeand change its label to
.
F s v- change the filter. Ifsis<, allow only events with labels belowto pass, if
sis>, allow only events with labels aboveto pass, and if
sis., reset the filter to none and ignore.
S v- find the event which occurred at time closest toand passing the filter. If there is a tie, choose the later one. Output this event's time.
Constraints
For all subtasks:
Subtask 1 [30%]
Subtask 2 [70%]
Input Specification
The first line will contain .
The next  lines will each contain 
 and 
 separated by a space.
The following line will contain .
The next  lines will each contain a query in the form described above.
Output Specification
The result of each query, one per line.
Sample Input
5
-2 1
0 4
3 -1
4 3
7 4
13
S -1
F > 3
S -4
S 4
T 7 9
S 4
F < -2
L 9 -3
S -3
F . 0
S 2
T 3 -3
S -3
Sample Output
0
0
7
0
9
3
-3
Explanation
The closest event to  is 
.
The filter is set to .
The closest event to  is 
, but 
 is not greater than 
, and for the next closest, 
, its label 
 is greater than 
.
The closest event to  is 
, but 
 is not greater than 
, and for the next closest, 
, its label 
 is greater than 
.
The time of event  is changed to 
.
The closest event to  with label greater than 
 is now 
.
The filter is set to . No events pass, but that is okay.
The label of event  is changed to 
. Now it passes the filter.
The closest event to  which passes the filter is 
.
The filter is cleared.
The closest event to  is 
.
The time of event  is changed to 
.
The closest event to  is 
.
Comments
If there are no events that pass the filter what should be printed? (I'm guessing -1 since that worked?)