PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000032. Lấy phần tử nhỏ thứ k rồi xóa (Data Structure)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Lấy phần tử nhỏ thứ k rồi xóa (Data Structure)
Data Structure
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Maintain a set of positive integers, initially empty. Operation 1 x inserts ; operation 2 k outputs the -th smallest element currently in and removes it. Every inserted value is guaranteed to be absent beforehand. Every extraction is guaranteed to have at least elements available.
Input
The first line contains . Each of the following lines contains . For type 2, the argument is the requested rank .
Output
For each type 2 operation, print the extracted value.
Subtasks
- Subtask 1 (20 points): ; ; ; insertion values are absent, and extraction ranks do not exceed the current set size.
- Subtask 2 (30 points): ; ; ; insertion values are absent, and extraction ranks do not exceed the current set size.
- Subtask 3 (50 points): ; ; ; insertion values are absent, and extraction ranks do not exceed the current set size.
Examples
Input
5
1 11
1 29
1 89
2 2
2 2
Output
29
89
Explanation
The set is {11,29,89}; extracting the second smallest removes 29 and then 89.