樣例過了 0分 誰能救救我
查看原帖
樣例過了 0分 誰能救救我
1557246
hater_heizi楼主2025/7/28 21:18
#include<bits/stdc++.h>
using namespace std;
multiset<int> st;
multiset<int>::iterator it,jt;
int main(){
	int m;
	cin>>m;
	int a,b;
	while(m--){
		cin>>a>>b;
		if (a==1){
			it=st.find(b);
			if (it!=st.end()){
				cout<<"Already Exist"<<endl;
			}
			else {st.insert(b);}
		}
		else if(a==2){
			if (st.empty()){
				cout<<"Empty"<<endl;
				continue;
			}
			it=st.find(b);
			if (it!=st.end()){
				cout<<*it<<endl;
				st.erase(it);
			}
			else {
				it=st.lower_bound(b);
				jt=st.upper_bound(b);
				if (it!=st.begin()){
					cout<<*(--it)<<endl;
					st.erase(it);
				}
				else if (jt!=st.end()){
					cout<<*jt<<endl;
					st.erase(jt);
				}
			}
		}
	}
}
2025/7/28 21:18
加载中...