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);
    }
}
posted @   f321dd  阅读(488)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示