Wowow
Time limit2sMemory limit512 MB
Maintain a dynamic set of (id, rating) friends under insertions, rating updates, and queries for the id holding the K-th highest rating.
- Level
Medium7 of 10
- Topics
- Segment tree, Binary search, Sorting, Array
- Solved
- No attempts yet
Problem
In the world of World of Warcraft, there is a fiercely competitive ranking ladder. Players change their ratings over time, and new players — including more and more of your friends — keep joining the game.
You and your friends want to keep a simple database of everyone's scores. As the computer scientist of the group, you have been put in charge of maintaining it. Don't let your friends down!
Input
The first line contains an integer (): the number of operations. Each of the next lines is one of the following three commands.
N X R— a new friend joins the database. () is the identifier of the new friend, and () is that friend's rating.M X R— modify an existing friend. is the identifier of a friend already in the database, and is that friend's new rating.Q K— a query. is an integer with , and it never exceeds the number of friends currently in the database.
Every rating value that appears anywhere in the input is distinct.
Output
For every Q K command, print one line with the identifier of the friend who has the -th highest rating in the database at that moment. refers to the top-rated friend, to the second-highest, and so on.