#C13076. Kth Element Set Operations

    ID: 42574 Type: Default 1000ms 256MiB

Kth Element Set Operations

Kth Element Set Operations

You are given a set that supports three operations on integer elements. The set is maintained in sorted order and may contain duplicate elements. The operations are as follows:

  1. Insertion: Insert an integer into the set while keeping the sorted order.
  2. Deletion: Delete the first occurrence of an integer from the set if it exists.
  3. K-th Smallest Query: Return the k-th smallest element in the set. If (k \le 0) or (k) is greater than the number of elements in the set, output invalid.

Your task is to process a sequence of operations. Each operation is given on a new line. The first line of input contains a single integer (n) denoting the number of operations. The following (n) lines each contain an operation in one of the following forms:

  • I x: Insert an integer x into the set.
  • D x: Delete the first occurrence of integer x from the set. If x is not present, do nothing.
  • K k: Print the k-th smallest element in the set. If \(k\) is out of range, print invalid.

Make sure your program reads from standard input and writes to standard output.

inputFormat

The first line of input contains an integer (n), the number of operations. Each of the following (n) lines contains a command in one of the following formats:

  • I x: Insert integer \(x\) into the set.
  • D x: Delete the first occurrence of integer \(x\) from the set.
  • K k: Output the k-th smallest element from the set (1-indexed). If \(k\) is invalid, output invalid.

All input values are separated by spaces.

outputFormat

For each query of the type K k, output the k-th smallest element on a new line. If the k-th element does not exist, print invalid (without quotes).## sample

6
I 3
I 1
I 2
K 2
K 1
K 3
2

1 3

</p>