QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#15264. GameZ Game Ranking System

Statistics

GameZ has launched a website for their latest game. Players from all over the world can upload their game scores to the website to see their global ranking. A higher score results in a higher rank. If two players have the same score, the one who uploaded their record first is ranked higher. Due to the popularity of the new game, the website's server is struggling under the load. GameZ has hired you to help them redevelop the core system.

The ranking system typically handles three types of requests: uploading a new score record, querying the current rank of a specific player, and returning the ranking records within a certain range. When a player uploads their latest score record, their previous score record is deleted. To reduce the server load, when returning ranking records within a range, at most 10 records are returned.

Input

The first line of the input contains an integer $n$ ($n \ge 10$), representing the total number of requests. The next $n$ lines each contain a request. The specific format of the requests is as follows:

  • +Name Score: Upload the latest score record. Name represents the player's name, consisting of uppercase English letters, not exceeding 10 characters. Score is a positive integer of at most 8 digits.
  • ?Name: Query the rank of a player. The player's score record must have already been uploaded previously.
  • ?Index: Return the names of up to 10 players starting from the Index-th rank. Index is guaranteed to be valid, i.e., not less than 1 and not greater than the total number of players currently recorded.

The total size of the input file does not exceed 2MB.

NOTE: Using C++ fstream to read large-scale data is relatively inefficient.

Output

For each query request, output the corresponding result. For requests in the ?Name format, output an integer representing the player's current rank. For requests in the ?Index format, output the names of up to 10 players starting from the Index-th rank on a single line, separated by spaces.

Examples

Input 1

20
+ADAM 1000000
+BOB 1000000
+TOM 2000000
+CATHY 10000000
?TOM
?1
+DAM 100000
+BOB 1200000
+ADAM 900000
+FRANK 12340000
+LEO 9000000
+KAINE 9000000
+GRACE 8000000
+WALT 9000000
+SANDY 8000000
+MICK 9000000
+JACK 7320000
?2
?5
?KAINE

Output 1

2
CATHY TOM ADAM BOB
CATHY LEO KAINE WALT MICK GRACE SANDY JACK TOM BOB
WALT MICK GRACE SANDY JACK TOM BOB ADAM DAM
4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.