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
 
题意:
有三种操作:0 a,将a加入容器,1 a 将a从容器中删去,2 a b 求大于a的第b个数。
代码:
 //求大于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);
add(a,);
}
else if(p==)
{
scanf("%d",&a);
if(sum(a)-sum(a-)==)
printf("No Elment!\n");
else add(a,-);
}
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; hdu2852 KiKi&#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. nginx实现请求转发

    反向代理适用于很多场合,负载均衡是最普遍的用法. nginx 作为目前最流行的web服务器之一,可以很方便地实现反向代理. nginx 反向代理官方文档: NGINX REVERSE PROXY 当在 ...

  2. 《sqoop安装和配置》

    参考帖子http://blog.csdn.net/jiedushi/article/details/6663177 http://blog.csdn.net/ww1982_0_0_0/article/ ...

  3. Unity3D NGUI刮刮卡效果

    线上效果 确保你的纹理的read/write 是勾选的,纹理格式是 RGBA32的 //代码 using UnityEngine; [RequireComponent(typeof(UITexture ...

  4. Java、JVM模型

    程序计数器:记录当前线程的执行位置(便于CPU切换线程的时候执行) 虚拟机栈:Java方法,方法从调用到执行完成对应一个栈帧从虚拟机栈入栈到出栈的过程. 本地方法区:Native方法(C++) 方法区 ...

  5. poj1001_Exponentiation_java高精度

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 162918   Accepted: 39554 ...

  6. 链表原地反转Demo

    现在就是Qt开发和给师弟师妹讲下数据结构吧,感觉还挺漫长的,上个Qt帖子等我把成品做出来再更. //Convert_plug.h #ifndef CONVERT #define CONVERT #de ...

  7. ASP.NET知识总结(7.状体保持)

    客户端的状态保持方案:ViewState.隐藏域.Cookies.控件状态.URL查询参数 服务端的状态保持方案:Session(会话).Application.Caching(缓存).DataBas ...

  8. win7远程桌面连接总是显示凭证不工作解决方法总结

    使用远程桌面连接可以在网络的另一端控制某台计算机,对计算机进行实时操作,但有时会出现连接失败的情况,比如总是显示您的凭证不工作,下面是我对此问题解决办法的总结. 方法一: 1.在开始菜单内的运行框里输 ...

  9. java获取汉字拼音首字母 --转载

    在项目中要更能根据某些查询条件(比如姓名)的首字母作为条件进行查询,比如查一个叫"李晓明"的人,可以输入'lxm'.写了一个工具类如下: import java.io.Unsupp ...

  10. JAVA中static关键字

    用法:是一个修饰符,用于修饰成员(成员变量,成员函数),不能用于修饰局部变量!被static修饰后,就多了一种调用方式,除了可以被对象调用外,还可以直接被类名调用,写法格式是:类名.静态成员.优点:被 ...