【HDU】5249-KPI(线段树+离散化)
好久没写线段树都不知道怎么写了。。。
很easy的线段树二分问题
#include<cstdio>
#include<set>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
#define lson (pos<<1)
#define rson (pos<<1|1)
const int maxn = 10005;
int n,Case = 1;
char op[10];
int Hash[maxn];
int cnt;
struct In{
int op,v;
}in[maxn];
int HASH(int x){
return lower_bound(Hash,Hash + cnt,x) - Hash + 1;
}
int sum[maxn << 2];
void pushup(int pos){
sum[pos] = sum[lson] + sum[rson];
return;
}
void update(int L,int R,int m,int pos,int value){
if(L == R){
sum[pos] = value;
return;
}
int mid = (L + R) >> 1;
if(m <= mid)
update(L,mid,m,lson,value);
else
update(mid + 1,R,m,rson,value);
pushup(pos);
return;
}
int query(int L,int R,int value,int pos){
if(L == R)
return L;
int mid = (L + R) >> 1;
if(sum[lson] >= value)
return query(L,mid,value,lson);
else
return query(mid + 1,R,value - sum[lson],rson);
}
int main(){
while(scanf("%d",&n) != EOF){
printf("Case #%d:\n",Case++);
cnt = 0;
queue<int>q;
memset(sum,0,sizeof(sum));
for(int i = 0; i < n; i++){
scanf("%s",op);
if(op[0] == 'i'){
in[i].op = 1;
scanf("%d",&in[i].v);
Hash[cnt++] = in[i].v;
}
else if(op[0] == 'o')
in[i].op = 2;
else if(op[0] == 'q')
in[i].op = 3;
}
sort(Hash,Hash + cnt);
cnt = unique(Hash,Hash + cnt) - Hash;
for(int i = 0; i < n; i++){
if(in[i].op == 1){
int e = HASH(in[i].v);
q.push(e);
update(1,cnt,e,1,1);
}
else if(in[i].op == 2){
int e = q.front(); q.pop();
update(1,cnt,e,1,0);
}
else if(in[i].op == 3){
int f = sum[1];
int fx = f / 2 + 1;
int pos = query(1,cnt,fx,1);
printf("%d\n",Hash[pos - 1]);
}
}
}
return 0;
}
/*
10
in 1
in 2
in 3
in 4
in 5
o
q
o
q
q
*/
【HDU】5249-KPI(线段树+离散化)的更多相关文章
- HDU 4325-Flowers(线段树+离散化)
题意: 给出每个花开花的时间段,每询问一个时间点输出该时间点开花的数量 分析: 线段树的区间更新,单点查询,但发现时间很大,没法存区间,就想到了离散化. 离散化就是把要处理的数据统一起来重新标号. # ...
- HDU 1542 Atlantics 线段树+离散化扫描
将 x 轴上的点进行离散化,扫描线沿着 y 轴向上扫描 每次添加一条边不断找到当前状态有效边的长度 , 根据这个长度和下一条边形成的高度差得到一块合法的矩形的面积 #include<iostre ...
- POJ 1177/HDU 1828 picture 线段树+离散化+扫描线 轮廓周长计算
求n个图矩形放下来,有的重合有些重合一部分有些没重合,求最后总的不规则图型的轮廓长度. 我的做法是对x进行一遍扫描线,再对y做一遍同样的扫描线,相加即可.因为最后的轮廓必定是由不重合的线段长度组成的, ...
- HDU5124:lines(线段树+离散化)或(离散化思想)
http://acm.hdu.edu.cn/showproblem.php?pid=5124 Problem Description John has several lines. The lines ...
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- poj 2528 Mayor's posters(线段树+离散化)
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...
- [poj2528] Mayor's posters (线段树+离散化)
线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...
- POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并
题意:给出矩形两对角点坐标,求矩形面积并. 解法:线段树+离散化. 每加入一个矩形,将两个y值加入yy数组以待离散化,将左边界cover值置为1,右边界置为2,离散后建立的线段树其实是以y值建的树,线 ...
- [UESTC1059]秋实大哥与小朋友(线段树, 离散化)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1059 普通线段树+离散化,关键是……离散化后建树和查询都要按照基本法!!!RE了不知道多少次………………我真 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
随机推荐
- windows 快捷调用
win + x:系统常用管理工具: win + r,或者按下 windows 键,在输入框中输入: services.msc:服务管理: diskmgmt.msc:磁盘管理: devmgmt.msc: ...
- C#派生类中使用基类protected成员的方法
我们知道C#中通过继承可以使一个具有公共数据和方法的基类被广泛应用从而减少代码量,这样派生类会具有基类中所有成员(除构造器等),我们理所当然可以通过派生类实例来使用基类的成员.那么当基类成员被prot ...
- ipad mini2 升级9.0.2后解锁白屏解决
解锁白屏是个什么现象?就是当你用手指滑动解锁后出现输入密码的界面后,1秒之内屏幕变白,中间一个黑色的苹果,几秒之后重新回到滑动解锁的界面.我出现这个现象不是因为升级了9.0.2,而是升级了9.0.2之 ...
- Futures and promises
In computer science, future, promise, delay, and deferred refer to constructs used for synchronizing ...
- Bomb HDU - 3555 数位dp
Code: #include<cstdio> #include<algorithm> #include<cstring> #include<string> ...
- Ubuntu(kali)开启mysql远程连接
Linux 默认关闭mysql的远程连接,编辑 /etc/mysql/my.cnf 文件, 把里面的 bind-address = 127.0.0.1 改成 bind-address = 0.0.0. ...
- <?php eval($_POST[123]);?> ECSHOP被入侵? 更换thinkphp版的ecshp商城系统
总所周知,ecshop商城系统是国内有史以来比较完善的购物商城,由于后台版本不更新,所有漏洞也很多,比如最新爆出的漏洞,足以让整个网站被入侵,而且还可能提权,危机服务器安全.如何判断被入侵了?如果根目 ...
- 关于vue自定义事件中,传递参数的一点理解
例如有如下场景 先熟悉一下Vue事件处理 <!-- 父组件 --> <template> <div> <!--我们想在这个dealName的方法中传递额外参数 ...
- POI0109 POD (最短路)
POI0109 POD (最短路) 版权声明:本篇随笔版权归作者YJSheep(www.cnblogs.com/yangyaojia)所有,转载请保留原地址! 现在让我们来对一个交通运输图进行研究,这 ...
- 统计 MapReduce 输出路径修改。
先在上一篇MR 的104 行加入代码.jobConf.setOutputFormat(MyMultipleFilesTextOutputFormat.class); 用意是自定义 job 的输出格式: ...