求调set算法
查看原帖
求调set算法
572956
wuhaoran2012楼主2023/7/20 13:19

请各位大佬指点一下

#include<bits/stdc++.h>
using namespace std;
#define low lower_bound
#define upp upper_bound
set<int>a;
int n;
int main()
{
	cin>>n;
	for(int i=1; i<=n; i++) {
		int c,b;
		cin>>c>>b;
		if(c==1) {
			int s=a.size();
			a.insert(b);
			if(a.size()==s) printf("Already Exist\n");
		} else {
			int d=INT_MAX,e=INT_MAX;
			if(a.empty()) {
				printf("Empty\n");
				return 0;
			}
			if(a.low(b)!=a.end()) d=*a.low(b);
			if(a.upp(b)!=a.begin()) e=*a.upp(b);
			if(d-b<b-e) printf("%d\n",d),a.erase(d);
			else printf("%d\n",e),a.erase(e);
		}
	}
	return 0;
}
2023/7/20 13:19
加载中...