Sherlock and Queries

0

0 votes
Medium-Hard
Problem

Sherlock has enrolled himself in a University to improve his Computer Science skills. This semester he had a course on Data Structures and was given the following problem for his end semester exams-
Design a suitable data structure which supports Q queries which can be of the following types:

  • 0 P - Insert an element P
  • 1 P - Delete an element P
  • 2 K - Let X be the Kth number from the beginning if the contents of data structure were sorted. Print the number of occurences of X in the data structure if there are at least K elements or else print -1.
    Note: Delete operation will only occur for elements already present in the data structure.

Input Format
First line contains Q, the number of queries.
Next Q lines contains queries of the mentioned types.

Constraints

  • 1Q2105
  • 1P109
  • 1K2105

Output Format
Output the answer to each query on a new line.

Sample Input
6
0 3
0 2
0 3
0 3
1 3
2 2
Sample Output
2
Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?