Alex and Priority Requests

2.3

3 votes
Approved, Maps, Medium, Sets, approved, hiring, recruit
Problem

Problem Statement:
Alex works in a firm that deals with the requests that come with their own \(Priority \space Value\) at different instants of time . Now he has to maintain a list of these requests with their \(Priority \space Value\) and the time at which they come. He updates the list according to the following queries:

\(Type \space 1:\) Update the \(Priority \space Value\) of the request at time t to p in the list. In case there is no request present at time t in list, set the \(Priority \space Value\) of that request to p at time t in the list.

\(Type \space 2:\) Remove the request which came at time t, from the list. It is guaranteed that some request has already been come at that time before. Alternatively, there will always be a request at time t currently present in the list.

\(Type \space 3:\) Print the minimum \(Priority \space Value\) of the request, followed by a space and the maximum \(Priority \space Value\) of the request currently present in the list.

\(Type \space 4:\) Print the \(Priority \space Value\) of the request, of the highest time present in the list.

Note:
1. The time instants given for query 1 may not be in ascending order.
2. There can be more than two time instants with same \(Priority \space Value\) of the request.

Constraints:
\( 1 < q < 2 \times 10^ 5\)
\( 1 < t,p< 2 \times 10^9 \)

Input Format:
First line of the input contains q, the number of queries.

Then q lines follow.

Each of the q lines correspond to one of the query mentioned above.

\(Type \space 1:\) Integer with value 1, followed by space and two space-separated integers p and t , denoting the \(Priority \space Value\) of the request and time t, respectively.

\(Type \space 2:\) Integer with value 2, followed by space and single integer t, denoting the time.

\(Type \space 3:\) Integer with value 3.

\(Type \space 4:\) Integer with value 4.

Output Format:

For each query of type 3 , output the minimum and maximum \(Priority \space Value\) of the request currently present in the list.

For each query of type 4, output the \(Priority \space Value\) of the request of highest time, currently present in the list.

Note: You can assume that whenever query of type \(3, 4\) occurs, the data is not null i.e some answer exists.

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

We set the \(Priority \space Value\) at time 3 to \(10\).

We set the \(Priority \space Value\) at time 5 to 2.

The minimum and maximum \(Priority \space Value\) present in the list are \(2, 10\).

The \(Priority \space Value\) at highest time (i.e \(t=5\) ) is 2.

We remove the \(Priority \space Value\) set at time 2 i.e we now just have \(Priority \space Value\) = \(10\) at time 2.

The minimum and maximum \(Priority \space Value\) present in the list are \(10, 10\) .

Editor Image

?