#K14571. Leaderboard System
Leaderboard System
Leaderboard System
You are given a system to maintain a leaderboard. Each operation is a command to either add/update a player's score or query a player's rank. The commands are:
add_score <player_id> <score>
: Adds a new player with the given score or updates the score of an existing player. If the player already exists, the new score replaces the previous one.get_rank <player_id>
: Queries the rank of the given player. The ranking is determined by sorting all players' scores in descending order. When multiple players have the same score, they share the same rank. The rank of a player is \(1+\) the number of distinct scores higher than that player's score.
For example, if the leaderboard has players with scores \(300, 200, 200, 100\), then the player with a score of \(300\) has rank 1, both players with score \(200\) have rank 2, and the player with \(100\) has rank 3.
inputFormat
The input is read from stdin in the following format:
N operation_1 operation_2 ... operation_N
The first line contains an integer N representing the number of operations. The following N lines each contain one operation. An operation is a string in one of the following two formats:
add_score <player_id> <score>
get_rank <player_id>
outputFormat
For each get_rank
operation, output the rank of the player on a separate line to stdout. No output is produced for add_score
operations.
7
add_score 1 100
add_score 2 200
get_rank 1
add_score 1 300
get_rank 1
get_rank 2
add_score 2 300
2
1
2
</p>