用auto定义指针为什么一直编译报错啊
查看原帖
用auto定义指针为什么一直编译报错啊
1159426
rome1楼主2023/12/28 22:51

RT 学的第一篇题解```

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,x,y;
map<int,int> m;
auto it,it2;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		if(x==1){
			if(m[y]==0)m[y]++;
			else {
				cout<<"Already Exist"<<endl;
			}
		}
		else{
			if(m.empty())cout<<"Empty";
			else if(m[y]==1){
					cout<<y<<endl;
					m.erase(y);
			}
			else {
				m[y]=1; 
                it=m.find(y); 
                it2=it;
                it++; 
                if(it2==m.begin()){ 
                    cout<<it->first<<endl;
                    m.erase(it);
                }
                else if(it==m.end()){ 
                    cout<<(--it2)->first<<endl;
                    m.erase(it2);
                }
                else if (y-(--it2)->first > it->first-y) {
                    cout<<it->first<<endl;
                    m.erase(it);
                }
                else {
                    cout<<it2->first<<endl;
                    m.erase(it2);
                }
                m.erase(y);
			}
		}
	}
}
2023/12/28 22:51
加载中...