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. Zabbix 4.0.24 完整安装

    依赖包安装: yum install net-snmp* libssh-devel libssh2-devel -y Zabbix server安装: wget https://cdn.zabbix. ...

  2. Linux学习笔记 | 常见错误之无法获得锁

    问题: 当运行sudo apt-get install/update/其他命令时,会出现如下提示: E: 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资 ...

  3. wpf 通过为DataGrid所绑定的数据源类型的属性设置Attribute改变DataGrid自动生成列的顺序

    环境Win10 VS2019 .Net Framework4.8 在wpf中,如果为一个DataGrid绑定到一个数据源,默认情况下DataGrid会为数据源类型的每个属性生成一个列(Column)对 ...

  4. 【Java】运算符(算术、赋值、比较(关系)、逻辑、条件、位运算符)

    运算符 文章目录 运算符 1. 算术运算符 2. 赋值运算符 3. 比较运算符 4. 逻辑运算符 5. 条件运算符 6. 位运算符 7. 运算符优先级 8. 运算符操作数类型说明 9.code 算术运 ...

  5. leetcode 940. 不同的子序列 II (动态规划 ,字符串, hash,好题)

    题目链接 https://leetcode-cn.com/problems/distinct-subsequences-ii/ 题意: 给定一个字符串,判断里面不相同的子串的总个数 思路: 非常巧妙的 ...

  6. Empire

    Empire 内网渗透神器 一 基本渗透 安装 git clone https://github.com/BC-SECURITY/Empire/ ./setup/install.sh 启动 ./emp ...

  7. 使用modify修改内表

    modify修改内表,有这样一种方式,MODIFY TABLE itab FROM wa [TRANSPORTING ..]. 然后这里的内表itab是有条件的,这个itab必须要有table key ...

  8. C++ STL 优先队列 (priority_queue)

    std::priority_queue <queue> 优先队列   优先队列是一种容器适配器,根据某些严格的弱排序标准,使其第一个元素始终包含的最大元素.   这种特性类似于堆,它可以在 ...

  9. 在HTML中改变input标签中的内容

    在HTML中改变input标签的内容 1.使用js自带的方法: document.getElementById('roadName').value='武汉路';//通过标签选择器来选择标签,然后设置值 ...

  10. GraphQL两年实战

    https://mp.weixin.qq.com/s/XIQ-0kRhjCe2ubBuhnhlQA