MSE07B - Double Queue

The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies.

As usual, each client of the bank is identified by a positive integer K and, upon arriving to the bank for some services, he or she receives a positive integer priority P. One of the inventions of the young managers of the bank shocked the software engineer of the serving system. They proposed to break the tradition by sometimes calling the serving desk with the lowest priority instead of that with the highest priority. Thus, the system will receive the following types of request:

0 The system needs to stop serving

1 K P Add client K to the waiting list with priority P

2 Serve the client with the highest priority and drop him or her from the waiting list

3 Serve the client with the lowest priority and drop him or her from the waiting list.

Your task is to help the software engineer of the bank by writing a program to implement the requested serving policy.

Input

Each line of the input contains one of the possible requests; only the last line contains the stop-request (code 0). You may assume that when there is a request to include a new client in the list (code 1), there is no other request in the list of the same client or with the same priority.

An identifier K is always less than 10^6, and a priority P is less than 10^7.The client may arrive for being served multiple times, and each time may obtain a different priority.

Output

For each request with code 2 or 3, the program has to print, in a separate line of the standard output, the identifier of the served client. If the request arrives when the waiting list is empty, then the program prints zero (0) to the output.

Sample

Input :
2 
1 20 14 
1 30 3 
2 
1 10 99 
3 
2 
2 
0 
Ouput: 
0 
20 
30 
10 
0 

Được gửi lên bởi:~!(*(@*!@^&
Ngày:2009-04-12
Thời gian chạy:0.200s-1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:Southeastern European 2007

hide comments
2021-05-27 18:02:04
Tham khảo: https://vnspoj.github.io/problems/MSE07B
2019-10-08 05:52:31
đấm bừa cx AC :))
2019-01-09 10:03:46
ôn set 1 chút
frostpixel aka.How 2 AC
2018-01-08 09:49:48 hồ vãn tuấn
lấy bộ test ở đâu nhỉ
2017-08-20 18:35:25 Con Bò Huyền Thoại
http://kienthuc24h.com/mse07b-spoj-double-queue/
2017-08-11 04:58:48
THAM KHẢO THUẬT TOÁN VÀ CODE TẠI:

http://yeulaptrinh.pw/937/mse07b-spoj/
2017-01-06 19:12:55 Lang Trat Y
Test chán quá.
Làm 2 thuật cho 2 bài toán cả 2 đều AC
1. Với yêu cầu 2 hoặc 3 thì khi phục vụ xong người nào thì hủy tất cả những yêu cầu trước đó của người đó.
2. Với yêu cầu 2 hoặc 3 thì khi phục vụ xong người nào thì chỉ hủy yêu cầu ở hiện tại.
Ví dụ: với cùng một input
VD:
[INPUT]
1 100 10
1 100 35
2
3
thì output cho bài toán 1 sẽ là
[OUTPUT]
100
0
và output của bài toán 2 sẽ là
[OUTPUT]
100
100
2016-10-11 15:10:14
Ghi nhầm truy vấn 2 thành 1, nhớ đời =)))
2016-08-12 19:13:07
C++ dùng set là AC
2016-07-26 10:21:59
Code 10 phút AC, phê vãi ~
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.