https://www.luogu.com.cn/problem/P5250?%ra=link
洛谷P5250【深基17.例5】木材仓库
我在接的时候报错了
作为小学生,还有很多不懂的地方,可以帮帮我吗?
代码:
#include<bits/stdc++.h>
#include<map>
using namespace std;
int n,op,t;
map<int,int> mp;
map<int,int>::iterator it,it2;
int main(){
/*freopen(".in","r",stdin);
freopen(".out","w",stdout);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision()<<x<<endl;
十年OI一场空,不开long long见祖宗
暴力出奇迹,打表过样例
*/
cin>>n;
for(int i = 1 ; i<=n ; i++){
cin>>op>>t;
if(op == 1){
if(mp.count(t)) cout<<"Already Exist\n";
else mp[t] = 1;
}else if(op == 2){
if(mp.empty()) cout<<"Empty\n";
else if(mp.count(t)){
mp.erase(t);
cout<<t<<endl;
}else{
mp[t] = 1;
it = mp.find(t);
it2 = it;
it++;
if(it == mp.begin()){
cout<<it->first<<endl;
mp.erase(it);
}else if(it == mp.end()){
cout<<(--it2)->first<<endl;
mp.erase(it2);
}
else if(t-(--it2)->first>it->first-t){
cout<<it->first<<endl;
mp.erase(it);
}
else{
cout<<it2->first<<endl;
mp.erase(it2);
}
mp.erase(t);
}
}
}
return 0;
}
问题报错
Process exited after 3.526 seconds with return value 3221226356