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's K-Number的更多相关文章

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

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

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

  3. hdu2852 KiKi&#39;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-2852 KiKi's K-Number---二分+树状数组

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

  6. hdu2852 KiKi's K-Number

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

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

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

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

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

  9. 2019牛客多校第四场K number dp or 思维

    number 题意 给一个数字串,问有几个子串是300的倍数 分析 dp写法:这题一看就很dp,直接一个状态dp[i][j]在第i位的时候膜300的余数是j左过去即可.这题比赛的时候样例老是少1,后面 ...

随机推荐

  1. java进阶(31)--TreeSet集合、TreeMap集合、自平衡二叉树

    一.TreeSet集合简单 1.TreeSet集合底层是一个TreeMap 2.TreeMap集合底层是一个二叉树 3.放到TreeSet集合的元素等同于放到TreeMap集合的Key部分 4.Tre ...

  2. WIN7系统没有USB驱动和以太网驱动如何操作

    |  欢迎关注个人公众号  zclinux_note  第一时间获取关于linux使用的技巧.探索Linux的奥秘   | 今天在单位安装了一台win7纯净版,但是安装完成后发现usb没有反应,插上网 ...

  3. 入门训练 - 蓝桥杯(Python实现)

    A+B问题: 题目: 资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 输入A.B,输出A+B. 输入格式 输入的第一行包括两个整数,由空格分隔,分别表示A.B. 输出格式 输出一行, ...

  4. 环境配置-Java-02-卸载

    1.卸载程序 在windows程序与功能中卸载Java相关的两个程序 2.删除环境变量 在windows环境变量中删除JAVA_HOME.CLASSPATH 以及 PATH中的两条路径 3.查看是否卸 ...

  5. 宝塔的url计划任务

    to通过url访问 就像访问你的网站一样 然后控制器/方法里面写你要做的操作 就可以了 ,简单的一批

  6. linux下安装nacos

    一.安装 1.下载安装包: https://github.com/alibaba/nacos/releases 2.解压 : tar -xzvf nacos-server-1.2.1.tar.gz 3 ...

  7. CMU数据库(15-445)实验2-b+树索引实现(上)

    Lab2 在做实验2之前请确保实验1结果的正确性.不然你的实验2将无法正常进行 环境搭建地址如下 https://www.cnblogs.com/JayL-zxl/p/14307260.html 实验 ...

  8. STL_list容器

    一.List简介 链表是一种物理存储单元上非连续.非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的. 链表由一系列结点(链表中每一个元素称为结点)组成,结点可以在运行时动态生成.每 ...

  9. c#使用谷歌身份验证GoogleAuthenticator

    此功能相当于给系统加了个令牌,只有输入对的一组数字才可以验证成功.类似于QQ令牌一样. 一丶创建最核心的一个类GoogleAuthenticator 此类包含了生成密钥,验证,将绑定密钥转为二维码. ...

  10. 一个关于ExecutorService shutdownNow时很奇怪的现象

    我们知道很多类库中的阻塞方法在抛出InterruptedException后会清除线程的中断状态(例如 sleep. 阻塞队列的take),但是今天却发现了一个特别奇怪的现象,先给出代码: publi ...