# hdu 2852 KiKi’s K-Number 题解【binary-lifting】【树状数组】

## Problem Description

For the $k$-th number, we all should be very familiar with it. Of course,to kiki it is also simple. Now Kiki meets a very similar problem, kiki wants to design a container, the container is to support the three operations.

Push: Push a given element $e$ to container

Pop: Pop element of a given $e$ from container

Query: Given two elements $a$ and $k$, query the $k$th larger number which greater than $a$ in container;

Although Kiki is very intelligent, she can not think of how to do it, can you help her to solve this problem?

## Input

Input some groups of test data ,each test data the first number is an integer $m (1\le m <100000)$, means that the number of operation to do. The next m lines, each line will be an integer p at the beginning, p which has three values:

If $p$ is $0$, then there will be an integer $e (0 <e <100000)$, means press element $e$ into Container.

If $p$ is $1$, then there will be an integer $e (0 <e <100000)$, indicated that delete the element $e$ from the container.

If $p$ is $2$, then there will be two integers $a$ and $k (0 <a <100000, 0 <k <10000)$,means the inquiries, the element is greater than $a$, and the $k$-th larger number.

## Output

For each deletion, if you want to delete the element which does not exist, the output “No Elment!”. For each query, output the suitable answers in line. If the number does not exist, the output “Not Find!”.

## Sample Input

5
0 5
1 2
0 6
2 3 2
2 8 1
7
0 2
0 2
0 4
2 1 1
2 1 2
2 1 3
2 1 4


## Sample Output

No Elment!
6
Not Find!
2
2
4
Not Find!


## Source

2009 Multi-University Training Contest 4 – Host by HDU

## Code：

#include<cstdio>
#include<cstring>
#define lowbit(x) (x&(-x))
#define N (1<<17)
int c[201000];//防止1<<17越界
{
while(p<=N)
{
c[p]+=x;
p+=lowbit(p);
}
}
{
int ans=0;
while(p)
{
ans+=c[p];
p-=lowbit(p);
}
return ans;
}
int main()
{
int n,op,u,v;
while(scanf("%d",&n)!=EOF)
{
memset(c,0,sizeof(c));
for(int i=1;i<=n;++i)
{
scanf("%d",&op);
if(op==0)
{
scanf("%d",&u);
}
else if(op==1)
{
scanf("%d",&u);
else
puts("No Elment!");
}
else
{
scanf("%d%d",&u,&v);
puts("Not Find!");
else
{
int p=0,sum=0;
for(int j=17;j>=0;--j)
if(sum+c[p+(1<<j)]<t)
{
p+=(1<<j);
sum+=c[p];
}
printf("%d\n",p+1);
}
}
}
}
return 0;
}



### 4 说点什么

0 Followers

Most reacted comment
2 Comment authors
Recent comment authors
Subscribe