String Query

0

0 votes
Map, Implementation, Recruit, Data Structures, Easy, Ready, Approved
Problem

You are given Q queries of two types to process:

  1. ADD value: You have to add a new string Value on the paper.
  2. SEARCH value: You have to find the first and last rank of the string value. This rank is actually the query number when this string is added and if that string has never occurred then output -1 -1.

Your are required to follow each of these query and print the answer. The given strings shall consist of lowercase English Letters, and their length shall not exceed 10.

Input:
First line: Q.
Next Q lines contains the desired queries.

Output:
Follow all the queries in the proper order and output the answer if asked in a new line.

Constraints:
1 <= Q <= 105
1 <= length(Value) <= 10

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first 3 queries string are respectively added on the paper and in the last queries you have the find the first and last occurrence of string "pranjuldb" and it occurred for the first time at query 1st and its last occurrence was query 3rd.

Editor Image

?