题目描述
思路
Online Solution
使用STL中的multiset
C++代码
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
multiset<LL> S;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt;
cin >> tt;
while(tt --){
int op, k;
LL x;
cin >> op;
if(op == 1){
cin >> x;
S.insert(x);
}else if(op == 2){
cin >> x >> k;
auto it = S.upper_bound(x);
while(k && it != S.begin()){
it --;
k --;
}
if(k == 0) cout << *it << '\n';
else cout << -1 << '\n';
}else{
cin >> x >> k;
auto it = S.lower_bound(x);
for(int i = 0; i < (k - 1); i ++){
if(it == S.end()) break;
it ++;
}
if(it != S.end()) cout << *it << '\n';
else cout << -1 << '\n';
}
}
return 0;
}