15007 - Appointment System   

Description

You are a software engineer hired by a dental clinic to implement an appointment management system that would allow clinic staffs to create and manage customer appointments. More specifically, your task is to design a C/C++ program that maintains the current appointment records and updates the appointment status according to the commands received.

Your program should support the following four commands:

  1. add N T Schedule an appointment for customer N at time T. If time T is already occupied by another customer, the command is considered invalid. Output -1 and do not modify the current appointment records.
  2. change N T1 T2 Change customer N's existing appointment from time T1 to time T2. If customer N does not have an appointment at T1, or if time T2 is already occupied by another customer, the command is considered invalid. Output -1 and do not modify the current appointment records.
  3. delete N T Cancel customer N's appointment at time T. If customer N does not have an appointment at time T, the command is considered invalid. Output -1 and do not modify the current appointment records.
  4. search T Query the customer who has an appointment after T. Find and output the name of the appointment with the smallest timestamp greater than T. If no such appointment exists, output -1.

Your program MAY use C/C++ standard library headers.

Input

The first line contains an integer M, representing the number of commands that follow. The next M lines each contain one command. Where:

  • N is the name of a customer and consists of English letters with a length between 1 and 50 characters (only lowercase).
  • T is an appointment time represented as a Unix epoch timestamp in seconds, where 0 <= T <= 253402300799.
  • M satisfies 1 <= M <= 5*10^5.
  • Every appointment time in the input is a valid date and time.

The format of every input command is guaranteed to be valid.

Output

For each command:

  • If the command is executed successfully:
    • add, change, and delete produce no output.
    • search outputs the name of the customer who has the appointment at the specified time.
  • If the command is invalid, output -1.

Each output should be terminated by a newline character ('\n'). An invalid command must not modify the current appointment records.

Sample Input  Download

Sample Output  Download

Tags

yan_ds



Discuss