uestc data structure D - 秋實大哥與戰爭

本來我是基本不會stl的,但這題還是讓我體會到了stl的有用,看來要把stl加入我的學習計劃了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<set>
#include<algorithm>
#define MAX 100010
using namespace std;

int main(){
	int n,m,t,x;
	cin>>n>>m;
	set<int>s;
	s.insert(0);
	s.insert(n+1);
	for(int i=0;i<m;i++){
		cin>>t>>x;
		if(t==0){
			s.insert(x);
		}
		else if(t==1){
			s.erase(x);
		}
		else if(t==2){
			if(s.count(x)){
				cout<<0<<endl;
				continue;
			}
			set<int>::const_iterator it=s.lower_bound(x),it2=it;
			it2--;
			cout<<*it-*it2-1<<endl;
		}
	}
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章