Bzoj 3685: General van Emde Boas tree

Source: Internet
Author: User

3685: General van Emde Boas treeDescription

Design data structure Support:
1 x If x does not exist, insert X
2 x if x exists, delete x
3 Output Current minimum value, if no output-1
4 output Current maximum value, if no output-1
5 x Output x precursor, if no output-1
6 x Output x successor, if not present output-1
7 x If x exists, output 1, otherwise output-1

Input

The first line gives the range and number of actions that N,M represents the number of occurrences
The next M-line gives the operation
N<=10^6,m<=2*10^6,0<=x<n

Sample Input10 11
1 1
1 2
1 3
7 1
7 4
2 1
3
2 3
4
5 3
6 2
Sample Output1
-1
2
2
2
-1Source

by Zky

Exercises

What is the VEB tree???。。。。

According to the description of the topic with a line of tree do just fine ....

Divide the interval by 0~n, and record the number of numbers that exist in the interval.

To mention the method of finding the precursor:

for X, in the whole interval to find x-1, each recursive two intervals, if the x-1 in the left interval, then the direct recursive left interval, if in the right interval, judge right interval there is no answer, not the current answer is the maximum value in the left interval.

The subsequent words find the same way.

#include <stdio.h> #include <iostream>using namespace std;const int n=1000005; #define P1 (p<<1) #    Define P2 (p<<1|1) int n,m,i,p,x,t[n<<2];inline void read (int &v) {char ch,fu=0; for (ch= ' * '; (ch< ' 0 ' | | Ch> ' 9 ') &&ch!= '-';    Ch=getchar ());    if (ch== '-') fu=1, Ch=getchar ();    for (v=0; ch>= ' 0 ' &&ch<= ' 9 '; Ch=getchar ()) v=v*10+ch-' 0 '; if (FU) v=-v;} void update (int l,int r,int x,int y,int p) {if (l==r) {T[p]=y;return;} int mid= (L+R) >>1;if (x<=mid) update (L,MID,X,Y,P1); else update (MID+1,R,X,Y,P2); t[p]=t[p1]+t[p2];} int min (int l,int R,int p) {if (!t[p]) return-1;if (l==r) return l;int mid= (l+r) >>1;if (T[P1]) return Min (L,MID,P1); El Se return Min (MID+1,R,P2);} int Max (int l,int r,int p) {if (!t[p]) return-1;if (l==r) return l;int mid= (l+r) >>1;if (T[P2]) return Max (MID+1,R,P2); else return Max (L,MID,P1);} int find (int l,int r,int X,int p) {if (!t[p]) return-1;if (l==r) return 1;int mid= (l+r) >>1;if (X<=mid) return find (l , mid,x, p1); else return find (MID+1,R,X,P2);} int pre (int l,int r,int X,int p) {if (x<0) return-1;if (!t[p]) return-1;if (l==r) return l;int mid= (l+r) >>1;if (x&lt ; =mid) return pre (L,MID,X,P1), Else{int tmp=pre (MID+1,R,X,P2), if (tmp==-1) return Max (L,MID,P1); else return tmp;}} int last (int l,int r,int X,int p) {if (x>n) return-1;if (!t[p]) return-1;if (l==r) return l;int mid= (l+r) >>1;if (X&G T;mid) return last (MID+1,R,X,P2), Else{int tmp=last (L,MID,X,P1), if (tmp==-1) return Min (MID+1,R,P2); else return tmp;}} int main () {read (n), read (m); for (i=1;i<=m;i++) {read (P); if (p==1) {read (x); update (0,n,x,1,1);} elseif (p==2) {Read (X ); update (0,n,x,0,1);} ElseIf (p==3) printf ("%d\n", Min (0,n,1)), ElseIf (p==4) printf ("%d\n", Max (0,n,1)), ElseIf (p==7) {read (x);p rintf ("%d\n" , find (0,n,x,1));} ElseIf (p==5) {read (x);p rintf ("%d\n", Pre (0,n,x-1,1)),} else{read (x);p rintf ("%d\n", Last (0,n,x+1,1));}} return 0;}

  

Bzoj 3685: General van Emde Boas tree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.