#K48277. MP3 Player Song Management
MP3 Player Song Management
MP3 Player Song Management
In this problem, you are required to implement an MP3 player to store and manage songs. The player supports two operations:
-
Add/Update Operation: Given a song ID, a genre (a string of at most 10 lowercase English letters), and a duration (in seconds), add a new song. If a song with the given ID already exists, update its genre and duration. Mathematically, if a song with ID (id) exists with details ((genre, duration)), then update it as follows: (song(id) := (new_genre, new_duration)).
-
Query Operation: Given a genre and a maximum duration (D), report the number of songs of that genre whose duration is (\leq D).
You will be given a sequence of operations. Each operation is specified on a separate line as described below.
inputFormat
The input begins with an integer (Q) representing the number of operations. Each of the next (Q) lines represents an operation in one of the following formats:
-
For an add/update operation:
1 song_id genre duration
Example:1 100 rock 240
-
For a query operation:
2 genre max_duration
Example:2 rock 200
All tokens are whitespace-delimited.
outputFormat
For each query operation (where the first integer is 2), output a single integer on a new line representing the number of songs of the specified genre with a duration less than or equal to the given maximum duration.## sample
5
1 1 rock 240
1 2 jazz 180
1 3 rock 120
2 rock 200
2 jazz 200
1
1
</p>