bzoj3685 普通van Emde Boas树

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3685

【题解】

写个set+fread即可。

# include <set>
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + 10;
const int mod = 1e9+7;

# define RG register
# define ST static

namespace FIFO {
    char ch,B[1<<20],*S=B,*T=B;
    #define getc() (S==T&&(T=(S=B)+fread(B,1,1<<20,stdin),S==T)?0:*S++)
    #define isd(c) (c>='0'&&c<='9')
    int aa,bb;int F(){
        while(ch=getc(),!isd(ch)&&ch!='-');ch=='-'?aa=bb=0:(aa=ch-'0',bb=1);
        while(ch=getc(),isd(ch))aa=aa*10+ch-'0';return bb?aa:-aa;
    }
}
#define gi FIFO::F()
#define BUFSIZE 5000000
namespace fob {char b[BUFSIZE]={},*f=b,*g=b+BUFSIZE-2;}
#define pob (fwrite(fob::b,sizeof(char),fob::f-fob::b,stdout),fob::f=fob::b,0)
#define pc(x) (*(fob::f++)=(x),(fob::f==fob::g)?pob:0)
struct foce {~foce() {pob; fflush(stdout);}} _foce;
namespace ib {char b[100];}
inline void pint(int x)
{
    if(x==0) {pc(48); return;}
    if(x<0) {pc('-'); x=-x;} //如果有负数就加上 
    char *s=ib::b;
    while(x) *(++s)=x%10, x/=10;
    while(s!=ib::b) pc((*(s--))+48);
}

int n, m;
set<int> s;
set<int>::iterator it;

int main() { 
    int opt, x;
    n = gi, m = gi;
    while(m--) {
        opt = gi;
        if(opt == 1) {
            x = gi;
            s.insert(x);
        }
        if(opt == 2) {
            x = gi;
            it = s.find(x);
            if(it != s.end()) s.erase(it);
        }
        if(opt == 3) {
            if(s.size() == 0) pint(-1); 
            else pint(*s.begin());
            pc(10); 
        }
        if(opt == 4) {
            if(s.size() == 0) pint(-1); 
            else pint(*--s.end());
            pc(10); 
        }
        if(opt == 5) {
            x = gi;
            it = s.lower_bound(x);
            if(it == s.begin()) pint(-1); 
            else pint(*--it);
            pc(10); 
        }
        if(opt == 6) {
            x = gi;
            it = s.upper_bound(x); 
            if(it == s.end()) pint(-1); 
            else pint(*it);
            pc(10); 
        }
        if(opt == 7) {
            x = gi;
            it = s.find(x); 
            if(it != s.end()) pint(1); 
            else pint(-1);
            pc(10); 
        }
    }
    return 0;
}
View Code

 

posted @ 2017-06-01 16:11  Galaxies  阅读(153)  评论(0编辑  收藏  举报