rt
用multiset
打的,超时了#8 #9 #10 #12
#include <bits/stdc++.h>
using namespace std;
multiset<int> q;
int n;
int main() {
ios::sync_with_stdio(false);
cin >> n;
while(n -- ) {
int opt, x;
cin >> opt >> x;
if(opt == 1) {
q.insert(x);
}
else if(opt == 2) {
multiset<int>::iterator it = q.lower_bound(x);
q.erase(it);
}
else if(opt == 3) {
int num = 0;
multiset<int>::iterator it = q.lower_bound(x);
for (multiset<int>::iterator i = q.begin(); i != it; ++ i, ++ num);
cout << num + 1 << endl;
}
else if(opt == 4) {
int num = 1;
for (multiset<int>::iterator i = q.begin(); i != q.end(); ++ i, ++ num)
if(num == x) {
cout << *i << endl;
break;
}
}
else if(opt == 5) {
multiset<int>::iterator it = q.lower_bound(x);
-- it;
cout << *it << endl;
}
else {
multiset<int>::iterator it = q.upper_bound(x);
cout << *it << endl;
}
}
return 0;
}