P2584 [ZJOI2006] GameZ Game Ranking System
Description
GameZ launched a website for their latest game, where players around the world can upload their game scores to see their global rankings. Higher scores rank higher. If two players tie, the one who uploaded earlier ranks higher. Due to the game's popularity, the website servers are under heavy load. GameZ has hired you to redevelop a new core system.
The ranking system needs to handle three types of requests: upload a new score record, query a player's current rank, and return the ranking records within a certain range. When a player uploads their latest score, their previous record will be removed. To reduce server load, when returning ranking records within a range, return at most $10$ records.
Input Format
The first line contains an integer $n$ ($n \ge 10$), the total number of requests. Each of the next $n$ lines contains one request, in one of the following formats:
``+Name Score`` Upload the latest score record. ``Name`` is the player's name, consisting of uppercase English letters, with length at most $10$ characters. ``Score`` is a positive integer with at most $10$ digits.
``?Name`` Query the player's rank. This player's score record is guaranteed to have been uploaded before.
``?Index`` Return at most $10$ player names starting from rank ``Index``. ``Index`` is guaranteed to be valid, i.e., it is at least $1$ and at most the current number of players with records.
Output Format
For each query request, output the corresponding result.
For a ``?Name`` request, output a single integer representing the player's current rank.
For a ``?Index`` request, output in one line the names of at most $10$ players starting from rank ``Index``, separated by single spaces.
Explanation/Hint
20
+ADAM 1000000 Add ADAM's score record.
+BOB 1000000 Add BOB's score record.
+TOM 2000000 Add TOM's score record.
+CATHY 10000000 Add CATHY's score record.
?TOM Output TOM's current rank.
?1 There are currently 4 players with records, so output ranks 1 to 4.
+DAM 100000 Add DAM's score record.
+BOB 1200000 Update BOB's score record.
+ADAM 900000 Update ADAM's score record (even if it is worse than before).
+FRANK 12340000 Add FRANK's score record.
+LEO 9000000 Add LEO's score record.
+KAINE 9000000 Add KAINE's score record.
+GRACE 8000000 Add GRACE's score record.
+WALT 9000000 Add WALT's score record.
+SANDY 8000000 Add SANDY's score record.
+MICK 9000000 Add MICK's score record.
+JACK 7320000 Add JACK's score record.
?2 There are currently 12 players with records, so output ranks 2 to 11.
?5 Output ranks 5 to 13.
?KAINE Output KAINE's rank.
The total size of the input file does not exceed 2 MB.
NOTE: Using C++ fstream to read large input is inefficient.
Translated by ChatGPT 5