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!
这题能够用树状数组做,查找用到了二分,二分用在树状数组上感觉如虎添翼(笑)。 这题查找的是比i这个数大d的位置是什么,所以仅仅要求出getsum(i)+d这个位置所相应的数是什么即可了。二分的时候要特殊推断一下。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define maxn 100505
int b[maxn],num[maxn]; int lowbit(int x){
return x&(-x);
}
void update(int pos,int num)
{
while(pos<=maxn){
b[pos]+=num;pos+=lowbit(pos);
}
} int getsum(int pos)
{
int num=0;
while(pos>0){
num+=b[pos];pos-=lowbit(pos);
}
return num;
} int find(int l,int r,int x)
{
int mid;
while(l<=r){
mid=(l+r)/2;
if(getsum(mid)>=x){
if(num[mid]==0){
r=mid-1;continue;
}
if(getsum(mid)-num[mid]<x){
return mid;
}
else r=mid-1;
}
else l=mid+1;
}
} int main()
{
int m,i,j,d,c,e;
while(scanf("%d",&m)!=EOF)
{
for(i=1;i<=maxn;i++){
b[i]=0;
num[i]=0;
}
for(i=1;i<=m;i++){
scanf("%d",&c);
if(c==0){
scanf("%d",&d);
num[d]++;
update(d,1);
}
else if(c==1){
scanf("%d",&d);
if(num[d]==0){
printf("No Elment!\n");continue;
}
num[d]--;
update(d,-1);
}
else if(c==2){
scanf("%d%d",&d,&e);
if(getsum(maxn)-getsum(d)<e){
printf("Not Find!\n");continue;
}
j=find(1,maxn,getsum(d)+e);
printf("%d\n",j);
}
}
}
return 0;
}

hdu2852 KiKi&#39;s K-Number的更多相关文章

  1. 树状数组求第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? ...

  2. 权值树状数组 HDU-2852 KiKi's K-Number

    引入 权值树状数组就是数组下标是数值的数组,数组存储下标对应的值有几个数 题目 HDU-2852 KiKi's K-Number 题意 几种操作,p=0代表push:将数值为a的数压入盒子 p=1代表 ...

  3. hdu2852 KiKi's K-Number

    Problem Description For the k-th number, we all should be very familiar with it. Of course,to kiki i ...

  4. 2019牛客网暑假多校训练第四场 K —number

    链接:https://ac.nowcoder.com/acm/contest/884/K来源:牛客网 题目描述 300iq loves numbers who are multiple of 300. ...

  5. hdu 2147 kiki&#39;s game, 入门基础博弈

    博弈的一些概念: 必败点(P点) : 前一个选手(Previous player)将取胜的位置称为必败点. 必胜点(N点) : 下一个选手(Next player)将取胜的位置称为必胜点. 必败(必胜 ...

  6. hdu-2852 KiKi's K-Number---二分+树状数组

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2852 题目大意: 题意:    给出三种操作,    0 在容器中插入一个数.    1 在容器中删 ...

  7. hdu2852 KiKi's K-Number

    题意:给定三个操作添加删除查询大于a的的第k大值----树状数组的逆向操作 给定a利用BIT查询有多少值比a小,这样比a大的k大值就应该有k+sum(a)个小于他的值 因此可以二分枚举k大值看看是不是 ...

  8. 2019牛客暑期多校训练营(第四场)K.number

    >传送门< 题意:给你一个字符串s,求出其中能整除300的子串个数(子串要求是连续的,允许前面有0) 思路: >动态规划 记f[i][j]为右端点满足mod 300 = j的子串个数 ...

  9. 2019牛客暑期多校训练营(第四场) - K - number - dp

    https://ac.nowcoder.com/acm/contest/884/K 一开始整了好几个假算法,还好测了一下自己的样例过了. 考虑到300的倍数都是3的倍数+至少两个零(或者单独的0). ...

随机推荐

  1. Elasticsearch--搜索

    目录 基本知识 查询结果返回设置:版本值.得分限制.定制返回字段 搜索类型 搜索执行偏好 基本查询 过滤器类型 高亮 控制高亮的片段 验证查询 数据排序 查询重写 基本知识 查询结果返回设置:版本值. ...

  2. Python代码搜索并下载酷狗音乐

    运行环境: Python3.5+Pycharm 实例代码: import requests,re keyword = input("请输入想要听的歌曲:") url = " ...

  3. MFC_1.1 基本知识

    如何创建一个MFC项目 选择 MFC 应用程序进行创建,不要使用非英文名 选择对话框风格进行编写 可以通过自定义的设置修改类名 MFC 的基本知识 MFC 是纯面向对象的编程,是 SDK 经过 C++ ...

  4. blender--(凹凸贴图)................https://jingyan.baidu.com/article/9f63fb917c4becc8400f0ea8.html

    在blender中直接绘制模型凹凸纹理细节 听语音 | 浏览:32 | 更新:2018-02-20 11:18 1 2 3 4 5 6 7 分步阅读 在blender中为了表现更多的模型细节,我们会常 ...

  5. 100 道 Linux 笔试题,能拿 80 分就算大神!

    本套笔试题共100题,每题1分,共100分.(参考答案在文章末尾) 1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统C. 跟踪管理系统信息和错 ...

  6. enote笔记语言(3)(ver0.3)

    章节:enote笔记语言(3)     what&why(why not)&how&when&where&which:紫色,象征着神秘而又潜蕴着强大的力量,故取 ...

  7. 洛谷——P1475 控制公司 Controlling Companies

    P1475 控制公司 Controlling Companies 题目描述 有些公司是其他公司的部分拥有者,因为他们获得了其他公司发行的股票的一部分.(此处略去一句废话)据说,如果至少满足了以下三个条 ...

  8. 简述Centos系统启动流程

    1. Centos5 POST开机自检 运行CMOS中的BIOS程序,加载第一个启动磁盘的Bootloader 由Bootloader读取kernel 通过挂载临时根目录initramfs加载核心模块 ...

  9. PAT 1079. 延迟的回文数

    PAT 1079. 延迟的回文数 给定一个 k+1 位的正整数 N,写成 ak...a1a0 的形式,其中对所有 i 有 0 <= ai < 10 且 ak > 0.N 被称为一个回 ...

  10. Python网络编程—socket(一)

    从今天开始python基础就介绍完毕了,下面我们将进阶到socket网络编程的介绍,那么socket是什么呢?我们带着这个问题开始今天的介绍: 一.socket初探 socket通常也称作" ...