#P2584. [ZJOI2006] GameZ游戏排名系统

    ID: 1597 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2006平衡树浙江O2优化哈希,HASH

[ZJOI2006] GameZ游戏排名系统

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 1010 records.

Input Format

The first line contains an integer nn (n10n \ge 10), the total number of requests. Each of the next nn 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 1010 characters. Score is a positive integer with at most 1010 digits.

?Name Query the player's rank. This player's score record is guaranteed to have been uploaded before.

?Index Return at most 1010 player names starting from rank Index. Index is guaranteed to be valid, i.e., it is at least 11 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 1010 players starting from rank Index, separated by single spaces.

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
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

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