#K38132. Dynamic Participant Manager

    ID: 26131 Type: Default 1000ms 256MiB

Dynamic Participant Manager

Dynamic Participant Manager

In this problem, you are required to implement a dynamic management system for participants. Each participant is identified by a unique integer ID and a unique name. The system supports the following operations:

  1. Add id name: Add a participant with the given id and name. If the id already exists, update the participant's name.
  2. Remove id: Remove the participant with the given id, if they exist.
  3. QueryID id: Return the name corresponding to the given id. If the id does not exist, return -1.
  4. QueryName name: Return the id corresponding to the given name. If the name does not exist, return -1.

For query operations, output the result in the order they appear. Note that only query operations produce output. All numbers and results should be handled as described.

The relationship can be mathematically described as follows: [ \text{queryById}(id) = \begin{cases} \text{name}(id) & \text{if } id \text{ exists}\ -1 & \text{otherwise} \end{cases} ]

and

[ \text{queryByName}(name) = \begin{cases} id & \text{if } name \text{ exists}\ -1 & \text{otherwise} \end{cases} ]

Your task is to simulate these operations based on the input provided from stdin and printing the outputs to stdout.

inputFormat

The input will be provided on standard input as follows:

  • The first line contains an integer n (n ≥ 1) representing the number of operations.
  • Each of the next n lines contains a single operation in one of the following formats:
    • Add id name
    • Remove id
    • QueryID id
    • QueryName name

Note: id is an integer and name is a string without spaces.

outputFormat

For every query operation (i.e. QueryID and QueryName), output the corresponding result on a new line in the exact order the queries appear in the input. Do not produce any output for the add or remove operations.## sample

6
Add 1 Alice
Add 2 Bob
QueryID 1
QueryName Bob
Remove 1
QueryID 1
Alice

2 -1

</p>