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. git删除本地分支失败,报错error: branch 'test219' not found.

    错误: 删除本地分支报错,操作如下: git branch -d test219 操作失败,错误信息:error: branch 'test219' not found git branch -D t ...

  2. python自动化--模块操作之re、MySQL、Excel

    一.python自有模块正则 import re # re.match只匹配字符串的开始,如果字符串开始不符合正则表达式,则匹配失败,函数返回None print(re.match("www ...

  3. 【转】jvm内存结构

    JVM的基本结构 包括四部分:类加载器.执行引擎.内存区(运行时数据区).本地方法接口 类加载器:jvm启动时或类运行时将需要的class文件加载到JVM中. JVM内存申请过程如下: JVM 会试图 ...

  4. form表单清空、重置

    form_live为formID <input type="button" value="重置" onclick="$('#form_live' ...

  5. blender_(uv应用)................http://digitalman.blog.163.com/blog/static/23874605620174172058299/

    轻松学习Blender基础入门之九:UV-1 2017-06-21 14:24:49|  分类: Blender |举报 |字号 订阅     下载LOFTER 我的照片书  |   [前言]     ...

  6. Compute和Linq的Field使用

    目录: Compute的使用 Field的使用 1.Compute 案例: private void ComputeBySalesSalesID(DataSet dataSet) { // Presu ...

  7. iptables详解(1):iptables概念

    所属分类:IPtables  Linux基础  基础知识  常用命令 这篇文章会尽量以通俗易懂的方式描述iptables的相关概念,请耐心的读完它. 防火墙相关概念 此处先描述一些相关概念. 从逻辑上 ...

  8. NOIp2017——追求那些我一直追求的

    谨以此祭奠我即将爆炸的NOIP2017. $Mingqi\_H\ \ 2017.09.24$ Day -47 突然发现半年来自己从来没有写对过SPFA,最近几天才发现自己的板子一直是错的...赶紧找个 ...

  9. Bat 脚本(常用命令)

    Bat 批处理脚本 (常用) Bat 批处理脚本 === Content === 1. Rem 和 :: Rem 为注释命令,能回显. :: 为符号注释,不能回显. %行内注释内容% ===== (不 ...

  10. 【ssm】spring功能讲解

    概览 Spring5框架包含许多特性,负责管理项目中的所有对象,并被很好地组织在下图所示的模块中 核心容器:由spring-beans.spring-core.spring-context.sprin ...