# KiKi's K-Number

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3864    Accepted Submission(s): 1715

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 kth 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 <= 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

``` //求大于a的第k个数就是求第sum(a)+k小的数。二分求第k小数。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int A[];
int m;
int lowbit(int x)
{
return x&(-x);
}
void add(int id,int val)
{
while(id<=)
{
A[id]+=val;
id+=lowbit(id);
}
}
int sum(int id)
{
int s=;
while(id>)
{
s+=A[id];
id-=lowbit(id);
}
return s;
}
int main()
{
int a,b,p;
while(scanf("%d",&m)!=EOF)
{
memset(A,,sizeof(A));
for(int i=;i<m;i++)
{
scanf("%d",&p);
if(p==)
{
scanf("%d",&a);
}
else if(p==)
{
scanf("%d",&a);
if(sum(a)-sum(a-)==)
printf("No Elment!\n");
}
else if(p==)
{
scanf("%d%d",&a,&b);
int tem=sum(a);
if(sum()-tem<b)
{
printf("Not Find!\n");
continue;
}
tem+=b;
int lef=,rig=,mid;
while(lef+<rig)        //二分结束条件！！！！！！！
{
mid=(lef+rig)>>;
int num=sum(mid);
if(num>=tem) rig=mid;
else lef=mid;
}
printf("%d\n",rig);
}
}
}
return ;
}```

## *HDU2852 树状数组(求第K小的数)的更多相关文章

1. 树状数组求第k小的元素

int find_kth(int k) { int ans = 0,cnt = 0; for (int i = 20;i >= 0;i--) //这里的20适当的取值,与MAX_VAL有关,一般 ...

2. hdu 4217 Data Structure? 树状数组求第K小

Data Structure? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

3. 树状数组求第K小值 (spoj227 Ordering the Soldiers &amp;amp;&amp;amp; hdu2852 KiKi&amp;#39;s K-Number)

题目:http://www.spoj.com/problems/ORDERS/ and pid=2852">http://acm.hdu.edu.cn/showproblem.php? ...

4. UVA11525 Permutation[康托展开 树状数组求第k小值]

UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ...

5. poj 2985 The k-th Largest Group 树状数组求第K大

The k-th Largest Group Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 8353   Accepted ...

6. HDU 5249 离线树状数组求第k大+离散化

KPI Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

7. POJ2985 The k-th Largest Group[树状数组求第k大值+并查集||treap+并查集]

The k-th Largest Group Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 8807   Accepted ...

8. HDU 2852 (树状数组+无序第K小)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2852 题目大意:操作①:往盒子里放一个数.操作②:从盒子里扔掉一个数.操作③:查询盒子里大于a的第K小 ...

9. 树状数组求第K大（From CLJ）

; <<log2[n];p;p>>=) if(a[ret+p]<=kth) kth-=a[ret+=p]; return ret;

## 随机推荐

1. poj 2186 Popular Cows

Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 29908   Accepted: 12131 De ...

2. BZOJ3282——Tree

1.题目大意:动态树问题,点修改,链查询xor和 裸题一道.. #include <stack> #include <cstdio> #include <cstdlib& ...

3. Swift初学习

距离swift发布10天了,也简单看了一下swift的语法,个人感觉相对于object-c很是简单明了.Swift的出现并不能说明iOS开发简单了很多,有可能会变得复杂,你需要学习两门编程语言,因为在 ...

4. Spring启动时加载数据

程序中也许有会有许多常用的,不会经常更改的数据,我们可以在程序初始化的时候就把他们加载,就不用频繁的加载或者查询. 以下是几个常用的,有COPY收集的,也有自己弄. 1. 实现BeanPostProc ...

5. mksquash_lzma-3.2 编译调试记录

今天在编译mksquash_lzma-3.2的时候出现了如下问题: /home/test/RT288x_SDK/toolchain/mksquash_lzma-3.2/lzma443/C/7zip/C ...

6. Oracle 创建分页存储过程（转帖）

原贴地址:http://19880614.blog.51cto.com/4202939/1316560 ps:源代码还有很多错误,我修改了 ------------------------------ ...

7. 微信内嵌H5网页 解决js倒计时失效

项目要求:将H5商城页面嵌套到公司微信公众号里 项目本身的开发跟移动端网页并无太多差异,只是这昨天遇到一个问题,说是棘手,到也简单. 用户下单后,在选择支付方式页面,有个倒计时的逻辑(从下单时开始计算 ...

8. create-react-app 打包后文件路径问题

在package.json 加入 "homepage": "需要的路径",

9. CodeForces - 896D ：Nephren Runs a Cinema（卡特兰数&amp;组合数学---比较综合的一道题）

Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. Howev ...

10. Linux mount指令