BZOJ 3685 普通van Emde Boas树 zkw线段树
2017-06-28 17:12
260 查看
#include <cstdio> #define N 4000005 #define ls(x) (x<<1) #define rs(x) (x<<1|1) #define pa(x) (x>>1) using namespace std; namespace IStream { char get_char() { const int L=1<<15; static char buffer[L]; static char *C,*mempool; if(C==mempool) mempool=(C=buffer)+fread(buffer,1,L,stdin); return *C++; } int read() { int re=0; char c; do c=get_char();while(c<'0' || c>'9'); while(c>='0' && c<='9') re=(re<<1)+(re<<3)+c-'0',c=get_char(); return re; } } int n,m,base,s ; void Insert(int x) { x+=base; if(s[x]) return ; while(x) ++s[x], x>>=1; return ; } void Delete(int x) { x+=base; if(!s[x]) return ; while(x) --s[x], x>>=1; return ; } int Querymin() { if(!s[1]) return 0; int x=1; while(x<=base) x=s[ls(x)] ? ls(x) : rs(x); return x-base; } int Querymax() { if(!s[1]) return 0; int x=1; while(x<=base) x=s[rs(x)] ? rs(x) : ls(x); return x-base; } int Querylower(int x) { for(x+=base;x>1;x>>=1) if((x&1) && s[pa(x)]>s[x]) break; if(x==1) return 0; --x; while(x<=base) x=s[rs(x)] ? rs(x) : ls(x); return x-base; } int Queryupper(int x) { for(x+=base;x>1;x>>=1) if(!(x&1) && s[pa(x)]>s[x]) break; if(x==1) return 0; ++x; while(x<=base) x=s[ls(x)] ? ls(x) : rs(x); return x-base; } int Queryexist(int x) { return s[base+x] ? 1 : -1; } int main() { using namespace IStream; n=read(), m=read(); base=1; while(base<=n) base<<=1; while(m--) { int mode=read(),x; if(mode!=3 && mode!=4) x=read()+1; if(mode==1) Insert(x); if(mode==2) Delete(x); if(mode==3) printf("%d\n",Querymin()-1); if(mode==4) printf("%d\n",Querymax()-1); if(mode==5) printf("%d\n",Querylower(x)-1); if(mode==6) printf("%d\n",Queryupper(x)-1); if(mode==7) printf("%d\n",Queryexist(x)); } return 0; }
相关文章推荐
- BZOJ 3685 普通van Emde Boas树 ZKW线段树
- BZOJ 3685 普通van Emde Boas树 zkw线段树
- 【BZOJ3685】【zkw权值线段树】普通van Emde Boas树
- 【bzoj3685】【普通van Emde Boas树】【线段树】
- bzoj-3685 普通van Emde Boas树 权值线段树+快读!
- BZOJ 3685: 普通van Emde Boas树( 线段树 )
- BZOJ_3685_普通van Emde Boas树_权值线段树
- BZOJ3685: 普通van Emde Boas树
- BZOJ3685 普通van Emde Boas树
- BZOJ 3685 zkw线段树 || 权值线段树
- BZOJ 3685 普通van Emde Boas树
- [BZOJ3685]普通van Emde Boas树
- BZOJ3685普通van Emde Boas树
- 【模板】BZOJ 3685: 普通van Emde Boas树——Treap
- BZOJ 3685 普通van Emde Boas树 权值线段树(zkw)
- 【权值分块】bzoj3685 普通van Emde Boas树
- bzoj3685: 普通van Emde Boas树
- BZOJ3685: 普通van Emde Boas树
- bzoj 3685 普通van Emde Boas树(坑)
- BZOJ3685 普通van Emde Boas树