题目大意:
都是中文,自己看吧。题目链接
题解:
看题目的第一眼就发现所有操作都可以用set。
但很明显会TLE,于是。。。。
加了个玄学读入优化,fread读入优化
然后就卡过了。。。。。
代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
#include<queue>
using std::set;
int n,m;
set<int>s;
inline char nc(){
static char buf[1000000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
char ch=nc();int sum=0;
while(!(ch>='0'&&ch<='9'))ch=nc();
while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
return sum;
}
int main()
{
n=read();m=read();
int x,y;
for(int i=1;i<=m;i++)
{
x=read();
if(x==1)
{
y=read();s.insert(y);
}
if(x==2)
{
y=read();s.erase(y);
}
if(x==3)
{
printf("%d\n",s.size()?*s.begin():-1);
}
if(x==4)
{
printf("%d\n",s.size()?*--s.end():-1);
}
if(x==5)
{
y=read();
set<int>::iterator yu=s.lower_bound(y);
printf("%d\n",yu!=s.begin()?*--yu:-1);
}
if(x==6)
{
y=read();
set<int>::iterator yu=s.upper_bound(y);
printf("%d\n",yu!=s.end()?*yu:-1);
}
if(x==7)
{
y=read();
printf("%d\n",s.count(y)?1:-1);
}
}
}