set 求助 不知道哪里错了
查看原帖
set 求助 不知道哪里错了
536617
AniuKarry楼主2023/7/14 23:34

rt


#include <bits/stdc++.h>
using namespace std;
#define ll long long
set<int> l;
const int inf = 0x3f3f3f3f;
const ll INF = 0x7fffffff;


int main() {
	//

	int n;
	cin >> n;
	int leng;
	set<int>::iterator check, f1, f2, f3;
	l.insert(-inf);
	l.insert(inf);
	for (int i = 1; i <= n; i++) {
		char p;
		cin >> p;
		if (p == '1') {
			cin >> leng;
			//check=l.find(leng);
			if (l.find(leng) == l.end()) {
				l.insert(leng);
				continue;
			} else {
				cout << "Already Exist" << endl;
				continue;
			}
		} else {
			cin >> leng;
			//check = l.find(leng);
			if (l.size() <= 2) {
				cout << "Empty" << endl;
				continue;
			} else if (l.find(leng) == l.end()) {
				cout << leng << endl;
				l.erase(leng);
				//cout << l.find(leng);
				continue;
			} else {
				f2 = l.find(leng);
				f1 = l.find(leng)--;
				f3 = l.find(leng)++;
				if (*f2 - *f1 <= *f3 - *f2) {
					cout << *f1 << endl;
					l.erase(*f1);
					continue;
				} else {
					cout << *f3 << endl;
					l.erase(*f3);
					continue;
				}
				l.erase(*f2);
			}



		}
	}

	return 0;
}
/*
in1:
7
1 1
1 5
1 3
2 3
2 3
2 3
2 3
out1:
3
1
5
Empty
*/


2023/7/14 23:34
加载中...