#K59077. Ranking System
Ranking System
Ranking System
You are given n players, and you need to implement a ranking system supporting two operations. There are two types of queries:
1 x p
: Add p points to player x.2 x
: Query the current rank of player x.
The ranking is determined as follows: players with a higher total score have a higher rank (i.e. a smaller rank number). In case of a tie (two players having the same score), the player who reached that score earlier (based on the order of updates) is ranked higher. You are to process the queries and, for each query of type 2, output the current rank of the queried player.
The problem involves understanding and implementing the ranking logic with careful tie-breaking. Note that the time when a player's current score is achieved is updated each time points are added.
For mathematical clarity, if we denote by \(S_i\) the score of player \(i\) and \(T_i\) the time (or order count) at which player \(i\) reached \(S_i\), then for a queried player \(x\), the rank is given by:
[ \text{rank}(x) = 1 + #{i \neq x : S_i > S_x \text{ or } (S_i = S_x \text{ and } T_i < T_x)}. ]
Your implementation should read from standard input and write to standard output.
inputFormat
The first line contains two integers n and q, representing the number of players and the number of queries respectively. Each of the following q lines contains a query in one of the following formats:
1 x p
— Add p points to player x.2 x
— Query the current rank of player x.
All input is provided via standard input (stdin). Note that player indices are 1-indexed.
outputFormat
For each query of type 2, output a single line containing the current rank of the queried player. The output should be written to standard output (stdout).## sample
5 6
1 1 10
1 2 20
1 3 15
2 1
2 2
2 3
3
1
2
</p>