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?

InputInput 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.
OutputFor 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! 思路:最后一个操作是时限的关键,而使用树状数组既能快速判断是否是第k大,也能满足前两种操作,套一个二分就行了(等补了线段树再做一次
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL; const int maxm = 1e5+;
const int INF = 0x3f3f3f3f; int C[maxm], n; void init() {
memset(C, , sizeof(C));
} void add(int pos, int val) {
for(; pos <= maxm; pos += lowbit(pos))
C[pos] += val;
} int getsum(int pos) {
int ret = ;
for(; pos; pos -= lowbit(pos))
ret += C[pos];
return ret;
} int biSearch(int a, int k) {
int l = , r = , mid, ans = -;
while(l <= r) {
mid = (l + r) >> ;
int t1 = getsum(mid), t2 = getsum(a);
if(getsum(mid) - getsum(a) >= k) {
ans = mid;
r = mid - ;
} else
l = mid + ;
}
return ans;
} int main() {
while(scanf("%d", &n) != EOF) {
init();
int type, t1, t2, jud;
for(int i = ; i < n; ++i) {
scanf("%d", &type);
if(type == ) {
scanf("%d", &t1);
add(t1, );
} else if(type == ) {
scanf("%d", &t1);
if(getsum(t1) - getsum(t1-) == )
printf("No Elment!\n");
else
add(t1, -);
} else if(type == ) {
scanf("%d%d", &t1, &t2);
jud = biSearch(t1, t2);
if(jud == -)
printf("Not Find!\n");
else
printf("%d\n", jud);
}
}
}
return ;
}
												

Day6 - F - KiKi's K-Number HDU - 2852的更多相关文章

  1. hdu 2852 KiKi's K-Number (线段树)

    版权声明:本文为博主原创文章,未经博主允许不得转载. hdu 2852 题意: 一个容器,三种操作: (1) 加入一个数 e (2) 删除一个数 e,如果不存在则输出 No Elment! (3) 查 ...

  2. 线段树 逆序对 Minimum Inversion Number HDU - 1394 Laptop

    Minimum Inversion Number HDU - 1394 求最小反转数,就是求最少的逆序对. 逆序对怎么求,就是先把所有的数都初始化为0,然后按照顺序放入数字,放入数字前查询从这个数往后 ...

  3. [笔记] $f(i)$ 为 $k$ 次多项式,$\sum_{i=0}^nf(i)\cdot q^i$ 的 $O(k\log k)$ 求法

    \(f(i)\) 为 \(k\) 次多项式,\(\sum_{i=0}^nf(i)\cdot q^i\) 的 \(O(k\log k)\) 求法 令 \(S(n)=\sum_{i=0}^{n-1}f(i ...

  4. HDU 2852 KiKi's K-Number 树状数组

    先补充从n个数中求第k小数的理论知识........ 睡觉去~ ------------------------------------------又要睡觉的分割线------------------ ...

  5. HDU 2852 (树状数组+无序第K小)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2852 题目大意:操作①:往盒子里放一个数.操作②:从盒子里扔掉一个数.操作③:查询盒子里大于a的第K小 ...

  6. HDU 2852 KiKi's K-Number(树状数组+二分搜索)

    题意:给出三种操作 0 e:将e放入容器中 1 e:将e从容器中删除,若不存在,则输出No Elment! 2 a k:搜索容器中比a大的第k个数,若不存在,则输出Not Find! 思路:树状数组+ ...

  7. HDU 2852 KiKi's K-Number 树状数组 + 二分

    一共最多才100000个数,并且数值范围0~100000. 树状数组 C[i] 记录数值为 i 的数有多少个. 删除时如果Query( a ) - Query( a - 1 ) == 0 则该数不存在 ...

  8. HDU 2852 KiKi's K-Number

    权值线段树 #include <cstdio> #include <cstring> const int N=200000,M=220000; int k,q,x,y,sum[ ...

  9. HDU 2852 KiKi's K-Number 主席树

    题意: 要求维护一个数据结构,支持下面三种操作: \(0 \, e\):插入一个值为\(e\)的元素 \(1 \, e\):删除一个值为\(e\)的元素 \(2 \, a \, k\):查询比\(a\ ...

随机推荐

  1. selenium 获取table数据

    public class Table { /** * @param args */ public static void main(String[] args) { // TODO Auto-gene ...

  2. c++模板(翁恺c++公开课[34-35]学习笔记)

    为什么要有模板(templates):当我们需要一个列表(list),列表中元素可能都为X类型也可能都为Y类型,怎么来实现呢? 定义基类?可以实现,很多情况下可能不够简明的表达设计思想 克隆代码(写一 ...

  3. C++启动和关闭外部exe

    转载:https://www.cnblogs.com/Sketch-liu/p/7277130.html 1.WinExec(  lpCmdLine: LPCSTR; {文件名和参数; 如没指定路径会 ...

  4. Android音频捕获(录音)(转)

    原文:http://www.yiibai.com/android/android_audio_capture.html Android有一个内置的麦克风,通过它可以捕获音频和存储,或在手机进行播放.有 ...

  5. mybatis利用generator自动生成的代码

    /** * 排序规则 */ protected String orderByClause; /** * 去重规则 */ protected boolean distinct; /** * where条 ...

  6. text-align:center;在ie7下,父级加上会让block状态的子元素居中。

    text-align:center:在ie7下,父级加上会让block状态的子元素居中.ie8以上不会.

  7. ch8 基于浮动的布局(两列浮动布局、三列浮动布局)

    CSS布局技术的根本是3个基本概念:定位.浮动.外边距操纵. 只需要设置希望定位的元素的宽度,然后将它们向左或向右浮动.因为浮动的元素不再占据文档流中的任何空间,它们就不再对包围他们的块框产生任何影响 ...

  8. 在java中调用python方法

    1.http://sourceforge.net/projects/jython/下载jython包,把其中的jython.jar添加到工程目录 示例: 1.摘自:http://blog.csdn.n ...

  9. 暑假周进度报告(三)-------版本过高后续问题处理,eclipse编译运行MapReduce以及Hadoop学习

    问题一:Hadoop版本太高 卸载Hadoop3.2.0 我改安装了Hadoop 2.7.7 如果没有权限下载.可以采用如下方式: 卸载完成以后返回原目录即可 后面的jdk卸载也可以采用这种方式. 按 ...

  10. linux之我的互联网面试经验

    互联网面试想必是每个学计算机的学生必不可少的环节,无论你的项目经验再多,你不准备基础知识,也还是无济于事.首先来说说关于工作的事情. 三年前,那时候我还是刚刚快要大四毕业的小鲜肉,那时候有个超大的招聘 ...