#K92677. Dynamic Scoreboard Ranking
Dynamic Scoreboard Ranking
Dynamic Scoreboard Ranking
You are organizing a coding competition and need to manage a dynamic scoreboard system. There are n participants (numbered from 1 to n) that initially have a score of zero. You will be given q queries. Each query is one of the following types:
U p s
: Update the score of participant p by adding s to their current score.Q p
: Query the rank of participant p. The rank is determined by the formula: $$rank = 1 + \#\{i \mid score_i > score_p\}.$$ That is, a participant’s rank is 1 plus the number of participants whose score is higher. If multiple participants have the same score, they share the same rank.
Your task is to implement the dynamic update and query operation for the scoreboard.
Note: There is no constraint on the number of queries so you should aim for a correct implementation even if a brute force approach is used.
inputFormat
The first line of input contains two integers n and q, where n is the number of participants and q is the number of queries to process.
Each of the next q lines contains a query in one of the following forms:
U p s
— update the score of participant p by adding integer s.Q p
— output the current rank of participant p.
All input is read from standard input (stdin).
outputFormat
For each query of type Q
, output a single line with the rank of the queried participant. All outputs should be written to standard output (stdout).
5 7
Q 1
U 1 10
U 2 15
Q 1
U 3 15
Q 2
U 2 5
Q 2
1
2
1
1
</p>