Alex and Priority Requests
Practice
2.3 (3 votes)
Approved
Maps
Medium
Sets
Approved
Hiring
Recruit
Problem
34% Success 2246 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
17 votes
Tags:
Basic ProgrammingImplementationMedium
Points:30
9 votes
Tags:
Mediumad hocapproved
Points:30
7 votes
Tags:
Basic ProgrammingBasics of ImplementationImplementationMediumadhoc