BZOJ3685: 普通van Emde Boas树
显然这题的所有操作都可以用set,但是直接用set肯定要T,考虑到读入量较大,使用fread读入优化,就可以卡过去了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include<cstdio> #include<set> using std::set; struct buf{ char z[3<<23],*s; buf():s(z){ z[ fread (z,1, sizeof z,stdin)]=0; } operator int (){ int x=0; while (*s<48)++s; while (*s>32) x=x*10+*s++-48; return x; } }it; int main(){ set< int >s; ~it; for ( int m=it;m;--m){ int o=it; if (o==1)s.insert(it); if (o==2)s.erase(it); if (o==3) printf ( "%d\n" ,s.size()?*s.begin():-1); if (o==4) printf ( "%d\n" ,s.size()?*--s.end():-1); if (o==5){ set< int >::iterator i=s.lower_bound(it); printf ( "%d\n" ,i!=s.begin()?*--i:-1); } if (o==6){ set< int >::iterator i=s.upper_bound(it); printf ( "%d\n" ,i!=s.end()?*i:-1); } if (o==7) printf ( "%d\n" ,s.count(it)?1:-1); } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步