Problem:
Set: Search

For a set $S$ of integers, perform a sequence of the following operations. Note that each value in $S$ must be unique.

insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.

find($x$): Report the number of $x$ in $S$ (0 or 1).

Input

The input is given in the following format.

$q$
$query_1$
$query_2$
:
$query_q$

Each query $query_i$ is given by

0 $x$

or

1 $x$

where the first digits 0 and 1 represent insert and find operations respectively.

Output

For each insert operation, print the number of elements in $S$.

For each find operation, print the number of specified elements in $S$.

Constraints

$1 \leq q \leq 200,000$

$0 \leq x \leq 1,000,000,000$

Sample Input 1

7
0 1
0 2
0 3
0 2
0 4
1 3
1 10

Sample Output 1

1
2
3
3
4
1
0

Solution in C (judge verdict: Accepted)

#include <stdio.h>

int search(int s[],int key,int head,int tail){
    if(head>tail)return -1;
    
    int mid=(head+tail)/2;
    
    if(s[mid]==key)return mid;
    else if(s[mid]>key)tail=mid-1;
    else if(s[mid]<key)head=mid+1;
    
    return search(s,key,head,tail);
}
int getLB(int s[],int key,int head,int tail){
    if(head>tail){
        if(tail<0)return 0;
        else return tail+1;
    }
    
    int mid=(head+tail)/2;
    
    if(s[mid]==key)return -1;
    else if(s[mid]<key)head=mid+1;
    else if(s[mid]>key){
        if(mid-1>=0&&s[mid-1]<key)return mid;
        else tail=mid-1;
    }
    return getLB(s,key,head,tail);
}
void sort(int s[],int sCnt,int key,int d){
    int i;
    for(i=sCnt;i>d;i--)s[i]=s[i-1];
    s[i]=key;
    return;
}
int insert(int s[],int sCnt,int key){
    if(search(s,key,0,sCnt-1)!=-1)return -1;
    
    int d=getLB(s,key,0,sCnt-1);
    sort(s,sCnt,key,d);
    
    return 0;
}

int main(void){
    int q;
    scanf("%d\n",&q);
    
    int s[q];
    int sCnt=0;
    
    int com,x;
    while(q--){
        scanf("%d %d\n",&com,&x);
        switch(com){
            case 0:
                //insert
                if(insert(s,sCnt,x)==0)sCnt++;
                printf("%d\n",sCnt);
                break;
            case 1:
                //find
                if(search(s,x,0,sCnt-1)==-1)printf("0\n");
                else printf("1\n");
                break;
        }
    }
    
    return 0;
}