Day6 - F - KiKi's K-Number HDU - 2852
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的更多相关文章
- hdu 2852 KiKi's K-Number (线段树)
版权声明:本文为博主原创文章,未经博主允许不得转载. hdu 2852 题意: 一个容器,三种操作: (1) 加入一个数 e (2) 删除一个数 e,如果不存在则输出 No Elment! (3) 查 ...
- 线段树 逆序对 Minimum Inversion Number HDU - 1394 Laptop
Minimum Inversion Number HDU - 1394 求最小反转数,就是求最少的逆序对. 逆序对怎么求,就是先把所有的数都初始化为0,然后按照顺序放入数字,放入数字前查询从这个数往后 ...
- [笔记] $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 ...
- HDU 2852 KiKi's K-Number 树状数组
先补充从n个数中求第k小数的理论知识........ 睡觉去~ ------------------------------------------又要睡觉的分割线------------------ ...
- HDU 2852 (树状数组+无序第K小)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2852 题目大意:操作①:往盒子里放一个数.操作②:从盒子里扔掉一个数.操作③:查询盒子里大于a的第K小 ...
- HDU 2852 KiKi's K-Number(树状数组+二分搜索)
题意:给出三种操作 0 e:将e放入容器中 1 e:将e从容器中删除,若不存在,则输出No Elment! 2 a k:搜索容器中比a大的第k个数,若不存在,则输出Not Find! 思路:树状数组+ ...
- HDU 2852 KiKi's K-Number 树状数组 + 二分
一共最多才100000个数,并且数值范围0~100000. 树状数组 C[i] 记录数值为 i 的数有多少个. 删除时如果Query( a ) - Query( a - 1 ) == 0 则该数不存在 ...
- HDU 2852 KiKi's K-Number
权值线段树 #include <cstdio> #include <cstring> const int N=200000,M=220000; int k,q,x,y,sum[ ...
- HDU 2852 KiKi's K-Number 主席树
题意: 要求维护一个数据结构,支持下面三种操作: \(0 \, e\):插入一个值为\(e\)的元素 \(1 \, e\):删除一个值为\(e\)的元素 \(2 \, a \, k\):查询比\(a\ ...
随机推荐
- PAT T1001 Battle Over Cities-Hard Version
按题意枚举每个点,建立缺少该点情况下的最小生成树,取权值最大的~ #include<bits/stdc++.h> using namespace std; ; const int inf= ...
- springmvc启动加载指定方法
官网: https://docs.oracle.com/javaee/7/api/javax/annotation/PostConstruct.htmlblog:https://blog.csdn.n ...
- Python学习笔记006
算术运算符 加+ 减- 乘* 除/ 整除//,地板除 取余% 指数** ()区分 优先级 比较运算符 赋值 = 等于 == 不等于 != 大于等于 >= 小于等于 <=
- EC20指令
SIM卡热插拔检测: AT+QSIMSTAT=1 //开启SIM卡热拔插状态报告AT+QSIMDET=1,1或AT+QSIMDET=1,0//开启 SIM卡检测功能当SIM卡拔出或者 ...
- 使用 TestFight 构建 Beta 测试版本
---恢复内容开始--- Beta测试属于软件开发周期中的一环,测试的重点就是让一些活生生的人去使用你的App,不断测试然后反馈.你需要让你的测试成员发现尽可能多的bug,以便你在公开发布之前将其修复 ...
- Mysql ,用户管理命令
添加用户.删除用户与授权以下对数据库的操作完全可以利用管理软件完成,比如在Navicat上进行操作,对数据库进行用户和权限管理. 1.创建用户:以root用户登录到数据库进行用户创建 命令: CREA ...
- 7(计算机网络) ICMP与ping
无论是在宿舍,还是在办公室,或者运维一个数据中心,我们常常会遇到网络不通的问题.那台机器明明就在那里,你甚至都可以通过机器的终端连上去看.它看着好好的,可是就是连不上去,究竟是哪里出了问题呢? ICM ...
- Spark 写 Hive table 非常慢【解决】
代码如下: dataFrame.createOrReplaceTempView("view_page_utm") val sql = s""" |in ...
- DateTime.Now.ToFileTime
var s = System.DateTime.Now.ToFileTime().ToString(); DateTime.Now.ToFileTime() 可以获得当前时间的长整型数字,这个数字应该 ...
- python表白代码1.0桃心输出
python爱心表达函数初级版本:def my_heart(a,b=2): print("\n".join(["".join([(a[(x-y) % len(a ...