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. bzoj1023: [SHOI2008]cactus仙人掌图

    学习了一下圆方树. 圆方树是一种可以处理仙人掌的数据结构,具体见这里:http://immortalco.blog.uoj.ac/blog/1955 简单来讲它是这么做的:用tarjan找环,然后对每 ...

  2. proj.4投影变换图示

  3. ubuntu16.04 NVIDIA显卡驱动安装

    安装环境:Ubuntu16.04 1.打开终端,先删除旧的驱动: sudo apt-get purge nvidia* 2禁用自带的 nouveau nvidia驱动 (important!) 创建一 ...

  4. 微信录音接口的调用以及amr文件转码MP3文件的实现

    最近实现录音功能,主要涉及到录音的上传和下载,以及转码问题.微信,QQ默认的的音频文件是amr格式的,而播放器却不识别amr格式的音频,必须尽行转码.amr文件分为两种,一种是通用的amr格式,这种文 ...

  5. Eclipse 的单步调试

    1.设置断点在程序里面放置一个断点,也就是双击需要放置断点的程序左边的栏目上. 2.调试(1)点击"打开透视图"按钮,选择调试透视图,则打开调试透视图界面,然后先设置断点,按调试按 ...

  6. ng-bind 与ng-model区别

    双向绑定,一般来说是这样 <input ng-model="object.xxx"> <span ng-bind="object.xxx"&g ...

  7. 【目录】Leetcode

    Leetcode 1.动态规划 Palindrome Partitioning II(hard) ☆ Distinct Subsequences(hard) Edit Distance (hard) ...

  8. MyEclipse2015配置Tomcat方法----》myeclipse2015

    1.打开Myeclipse2015,进入偏好设置window-perference,找到下图箭头指向的地方 2.点击Add按钮进入下面界面 3.点击next进入下面界面 4.选择tomat  选择JR ...

  9. ImageView属性

    一.结构 java.lang.Object android.view.View android.widget.ImageView 已知直接子类: ImageButton, QuickContactBa ...

  10. CSS基础及选择器

    CSS层叠样式表与表相分离.常用CSS2和CSS3. HTML引入CSS 1.行内样式 <div style="color:red"></div> 2.内部 ...