Queries
Time limit10sMemory limit128 MB
Maintain a point set under deletions and report the leftmost point within S below the current highest y, breaking ties by higher y.
- Level
Medium6 of 10
- Topics
- Segment tree, Sorting
- Solved
- No attempts yet
Problem
You are given a set of points Z and a tolerance value S. Write a program that processes two kinds of operations:
- Remove: delete a given point from the set Z.
- Find: report the "upper-left point" of the set Z.
The upper-left point is defined as follows. Let be the largest -coordinate among the points currently in Z. Consider as candidates every point whose -coordinate is smaller than by at most S, that is, every point with . Among the candidates, the upper-left point is the one with the smallest -coordinate (the leftmost one). If several candidates share the smallest -coordinate, choose the one with the largest -coordinate (the highest one).
Input
The first line contains the number of test cases (). The test cases follow.
The first line of each test case contains two space-separated integers and (, ), the initial size of the set Z and the tolerance value. Each of the next lines contains two space-separated integers and (), describing a point of Z. All points within one test case are distinct.
The next line contains an integer (), the number of operations to perform. Each of the following lines has one of the two forms:
USUN: remove the point from the set Z.ZNAJDZ: find the upper-left point.
A point named in a remove operation is guaranteed to be present in Z at that moment. A find operation is never issued while Z is empty.
Output
For every find (ZNAJDZ) operation, print the coordinates of the found point as x y on its own line.