#C14081. Threatened Species Database Manager

    ID: 43691 Type: Default 1000ms 256MiB

Threatened Species Database Manager

Threatened Species Database Manager

You are given the task of managing a database for threatened species. You need to support three types of operations: ADD, UPDATE, and QUERY. The allowed threat levels are \(\{\texttt{vulnerable}, \texttt{endangered}, \texttt{critically endangered}\}\).

The operations are defined as follows:

  • ADD species_name threat_level: Adds a new species with the given threat level. If the threat level is not one of the allowed values, output Invalid threat level (and do not add the species).
  • UPDATE species_name new_threat_level: Updates the threat level of an existing species. If the species does not exist, output Species species_name does not exist (with species_name replaced by the actual name). If the new threat level is invalid, output Invalid threat level.
  • QUERY threat_level: Lists all species with the specified threat level in lexicographical order. If the threat level is invalid, output Invalid threat level. If no species have that threat level, output None.

Each error message or query response should be printed immediately on a new line.

Note: Handle all input from standard input and output your answers to standard output.

inputFormat

The first line contains an integer \(T\) which denotes the number of operations. The following \(T\) lines each contain an operation in one of the following formats:

  • ADD species_name threat_level
  • UPDATE species_name new_threat_level
  • QUERY threat_level

Each component is separated by whitespace. All operations are processed in order.

outputFormat

For each operation:

  • If an invalid threat level is encountered (in ADD, UPDATE, or QUERY), output Invalid threat level.
  • If an UPDATE operation targets a non-existent species, output Species species_name does not exist.
  • For a QUERY operation with a valid threat level:
    • If there are species with the queried threat level, output their names in lexicographical order separated by a single space.
    • If no species match, output None.

Print each result or error message on a new line as they occur.

## sample
6
ADD Tiger endangered
ADD Panda endangered
QUERY endangered
UPDATE Tiger critically\ endangered
QUERY endangered
QUERY critically\ endangered
Panda Tiger

Panda Tiger

</p>