set偷鸡解法,求助
查看原帖
set偷鸡解法,求助
1155764
ouxiyao楼主2025/2/7 20:45
#include<bits/stdc++.h>
using namespace std;
int a[65536],la;
set<int>s;
set<int>::iterator it;
int main(){
	int n,m,x;
	cin>>n>>m;
	char op;
	for(int i = 1;i<=m;i++){
		cin>>op;
		if(op=='D'){
			cin>>x;
			s.insert(x);
			a[++la] = x;
		}
		else if(op=='R'){
			it = s.find(a[la]);
			s.erase(it);
			la--;
		}
		else{
			cin>>x;
			it = s.lower_bound(x);
			if(*it==x)cout<<0<<'\n';
			else {
				int f = 0,t = n,g = 0;
                if(it!=s.end())t = *it,g++;
                if(it!=s.begin())f = *(--it),g++;
                if(g==2)cout<<t-f-1<<'\n';
                else cout<<t-f<<'\n';
			}
		}
	}
	return 0;
}
2025/2/7 20:45
加载中...