蒟蒻萌新ABC241的D题求助
  • 板块学术版
  • 楼主忘怜城羡
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/7/9 20:55
  • 上次更新2023/10/27 21:18:59
查看原帖
蒟蒻萌新ABC241的D题求助
374756
忘怜城羡楼主2022/7/9 20:55

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);
			}
		}
	}
}
2022/7/9 20:55
加载中...