#K44402. Dynamic Ranking System
Dynamic Ranking System
Dynamic Ranking System
This problem involves implementing a Dynamic Ranking System that maintains a list of players' scores and processes a series of operations. You are given an initial list of scores, and then a number of operations to perform on this list. The operations can update a score, sort the entire list, or query for certain values.
The supported operations are as follows:
- UPD i x: Update the score of the i-th player to x (1-indexed).
- SRT: Sort the entire list of scores in non-decreasing order. This operation modifies the list permanently.
- QRY k: Output the k-th smallest score in the current list (by considering a sorted copy of the current list without changing it permanently).
- QMIN: Output the minimum score in the current list.
- QMAX: Output the maximum score in the current list.
You need to process the operations in the order they are given. For every query operation (QRY
, QMIN
, QMAX
), output the resulting value on a separate line.
The mathematical formulation of the k-th smallest element can be described as finding the score s such that:
where \(S\) is the current list of scores.
inputFormat
The input is read from stdin and has the following format:
- An integer n representing the number of players.
- A line containing n space-separated integers representing the initial scores of the players.
- An integer m representing the number of operations.
- m lines each containing an operation command. The operations are one of the following:
UPD i x
SRT
QRY k
QMIN
QMAX
outputFormat
For each query operation (QRY
, QMIN
, QMAX
), output the result on a new line to stdout.
5
50 30 20 40 10
7
SRT
UPD 3 35
QRY 3
QMIN
QMAX
SRT
QRY 4
35
10
50
40
</p>