用set过了样例但是测试点全WA
查看原帖
用set过了样例但是测试点全WA
940317
lightme楼主2023/11/18 22:07
// Problem: 
//     P5250 【深基17.例5】木材仓库
//   
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P5250
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
//#include<cstdio>
#include<cmath>
#include<set>
#define ll long long  
#define endl '\n'
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(a);i>(b);i--)
//#define N 1000100 //1e6+100 
 
using namespace std;
int n,x,y;
int f,e;
set<int>s;

int main(){
	//ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	set<int>::iterator it;
	while(n--){
		cin>>x>>y;
		if(x==1){
			if(s.find(y)==s.end()) s.insert(y);
			else cout<<"Already Exist"<<endl;
		}else if(x==2){
			if(s.empty()){
				cout<<"Empty"<<endl;
				continue;
			}
			it=s.lower_bound(y);
			if(it==s.end()){
				cout<<*(--it)<<endl;
				s.erase(*it);
			}
			else{
				e=*it;
				f=*(--it);
				if(abs(e-y)>=abs(f-y)){
					cout<<f<<endl;
					s.erase(f);
				}else{
					cout<<e<<endl;
					s.erase(e);
				}
			}
		}
	}
	return 0; 
} 


代码求调

2023/11/18 22:07
加载中...