A22个,T7个,代码如下
#include<bits/stdc++.h>
#define int long long
using namespace std;
multiset<long long> se;
signed main()
{
int n;
scanf("%lld",&n);
for(int i(1);i<=n;++i)
{
int u,x,k;
scanf("%lld",&u);
if(u==1)
{
scanf("%lld",&x);
se.insert(x);
}
else
{
scanf("%lld%lld",&x,&k);
if(u==2)
{
multiset<int>::iterator it=se.upper_bound(x);
bool op=0;
for(int j(1);j<=k;++j)
{
if(it==se.begin())
{
op=1;
break;
}
it--;
}
if(op==1)
printf("-1\n");
else
printf("%lld\n",*it);
}
else
{
multiset<int>::iterator it=se.lower_bound(x);
bool op=0;
if(it==se.end())
op=1;
for(int j(1);j<k;++j)
{
it++;
if(it==se.end())
{
op=1;
break;
}
}
if(op==1)
printf("-1\n");
else
printf("%lld\n",*it);
}
}
}
}