求助大佬!set写的,样例通过,但全WA了
查看原帖
求助大佬!set写的,样例通过,但全WA了
428535
Dgucheng楼主2022/4/4 17:30
#include<bits/stdc++.h>
using namespace std;

int n;
set <int> pp;
set<int>::iterator it,t;

int main(){
	cin >> n;
	for (int i=0;i<n;i++){
		int a,b;
		cin >> a >> b;
		if (a==1){
			t=pp.find(b);
			if (*t==b)
				cout << "Already Exist" << endl;
			else
				pp.insert(b);
		}
		else{
			if (pp.empty()){
				cout << "Empty" << endl;
			}
			else{
				it=pp.lower_bound(b);
				if (*it==b){
					cout << b << endl;
					pp.erase(b);
				}
				else if (it==pp.end()){
					int x;
					x=*it;
					cout << x << endl;
					pp.erase(x);
				}
				else{
					int x,y;
					y=abs((*it--) -b);
					x=abs(*it-b);
					if (x<=y){
						cout << *it << endl;
						pp.erase(*it);
					}
					else{
						cout << *++it << endl;
						pp.erase(*it);
					}
				}
			}
		}
	}
	return 0;
}
2022/4/4 17:30
加载中...