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. 【bzoj2318】Spoj4060 game with probability Problem

    题目描述 Alice和Bob在玩一个游戏.有n个石子在这里,Alice和Bob轮流投掷硬币,如果正面朝上,则从n个石子中取出一个石子,否则不做任何事.取到最后一颗石子的人胜利.Alice在投掷硬币时有 ...

  2. 第2月第25天 BlocksKit

    1.blockskit https://github.com/zwaldowski/BlocksKit bk_showAlertViewWithTitle 2.toast +(void)showToa ...

  3. (转载)robots.txt写法大全和robots.txt语法的作用

    1如果允许所有搜索引擎访问网站的所有部分的话 我们可以建立一个空白的文本文档,命名为robots.txt放在网站的根目录下即可.robots.txt写法如下:User-agent: *Disallow ...

  4. iOS开发——高级篇——音频、音乐播放(封装类)

    一.简介 简单来说,音频可以分为2种音效又称“短音频”,通常在程序中的播放时长为1~2秒在应用程序中起到点缀效果,提升整体用户体验 音乐比如游戏中的“背景音乐”,一般播放时间较长 播放音频可以使用框架 ...

  5. 双系统Ubuntu分区扩容过程记录

    本人电脑上安装了Win10 + Ubuntu 12.04双系统.前段时间因为在Ubuntu上做项目要安装一个比较大的软件,导致Ubuntu根分区的空间不够了.于是,从硬盘又分出来一部分空间,分给Ubu ...

  6. Hbuilder MUI 选择器(Picker)设置默认选项

    mui 联动选择初始化很多人都遇到问题,就是setselectedvalue 不好用,实际上这个地方应该是有bug的 所以只能用setselectedindex 来实现 下面我是我的实现方式供大家参考 ...

  7. ABAP 客户报表

    *&---------------------------------------------------------------------* *& Report  ZSDR014 ...

  8. 二、CoreAnimation之寄宿图详解

    在之前的图层树中我们知道,可以使用CALayer对象创建一些有背景颜色的图层,其实使用CALayer,不仅可以利用其展示背景颜色,还可以展示图片.而这些展示内容,其实就是CALayer的寄宿图.这一节 ...

  9. Qt 配置文件QSettings

    QString appDirPath = QCoreApplication::applicationDirPath(); QSettings* configIniRead = new QSetting ...

  10. ios升级<注:来着微信平台>

    <来着微信平台>  http://mp.weixin.qq.com/s?__biz=MjM5NTIyNTUyMQ==&mid=2709545194&idx=1&sn ...