poj3667(线段树)
题目连接:http://poj.org/problem?id=3667
题意:1 a:询问是不是有连续长度为a的空房间,有的话住进最左边
2 a b:将[a,a+b-1]的房间清空
线段树操作:update:区间替换 query:询问满足条件的最左断点
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define M 1000000000
#define maxn 55555
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
int lsum[maxn<<],rsum[maxn<<],sum[maxn<<];
int col[maxn<<];
void PushDown(int rt,int m)
{
if(col[rt]!=-)
{
col[rt<<]=col[rt<<|]=col[rt];
sum[rt<<]=lsum[rt<<]=rsum[rt<<]=col[rt]?:m-(m>>);
sum[rt<<|]=lsum[rt<<|]=rsum[rt<<|]=col[rt]?:m>>;
col[rt]=-;
}
}
void PushUp(int rt,int m)
{
lsum[rt]=lsum[rt<<];
rsum[rt]=rsum[rt<<|];
if(lsum[rt]==m-(m>>))lsum[rt]+=lsum[rt<<|];
if(rsum[rt]==m>>)rsum[rt]+=rsum[rt<<];
sum[rt]=max((lsum[rt<<|]+rsum[rt<<]),max(sum[rt<<],sum[rt<<|]));
}
void build(int l,int r,int rt)
{
col[rt]=-;
sum[rt]=lsum[rt]=rsum[rt]=r-l+;
if(l==r)return;
int m=(r+l)>>;
build(lson);
build(rson);
}
void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
sum[rt]=lsum[rt]=rsum[rt]=c?:r-l+;
col[rt]=c;
return;
}
PushDown(rt,r-l+);
int m=(r+l)>>;
if(L<=m)update(L,R,c,lson);
if(R>m)update(L,R,c,rson);
PushUp(rt,r-l+);
}
int query(int w,int l,int r,int rt)
{
if(l==r)return l;
PushDown(rt,r-l+);
int m=(r+l)>>;
if(sum[rt<<]>=w)return query(w,lson);
else if(rsum[rt<<]+lsum[rt<<|]>=w)return m-rsum[rt<<]+;
else return query(w,rson);
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)>)
{
build(,n,);
while(m--)
{
int a,b,op;
scanf("%d",&op);
if(op==)
{
scanf("%d",&a);
if(sum[]<a)puts("");
else
{
int ans=query(a,,n,);
printf("%d\n",ans);
update(ans,ans+a-,,,n,);
}
}
else
{
scanf("%d%d",&a,&b);
update(a,a+b-,,,n,);
}
}
}
}
poj3667(线段树)的更多相关文章
- poj3667 线段树 区间合并
//Accepted 3728 KB 1079 ms //线段树 区间合并 #include <cstdio> #include <cstring> #include < ...
- poj3667(线段树区间合并&区间查询)
题目链接: http://poj.org/problem?id=3667 题意:第一行输入 n, m表示有 n 间房间(连成一排的), 接下来有 m 行输入, 对于接下来的 m 行输入: 1 x : ...
- poj3667 Hotel (线段树 区间合并)
poj3667 HotelTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 18925 Accepted: 8242Descripti ...
- poj3667【线段树】/【类似权值线段树写法】
题意:n个空房间.两种操作:1.选择最小的连续D个房间入住,并输出这连续D个房间的最小标号.2.将某个区间内的房间全部退房. #include <cstdio> #include < ...
- poj-3667(线段树区间合并)
题目链接:传送门 参考文章:传送门 思路:线段树区间合并问题,每次查询到满足线段树的区间最左值,然后更新线段树. #include<iostream> #include<cstdio ...
- 【POJ3667】Hotel(线段树)
题意:有n个依次编号的元素,要求维护以下两个操作: 1.询问整个数列中是否有长度>=x的连续的一段未被标记的元素,若无输出0,若有输出最小的开始编号ans并将[ans,ans+x-1]标记 2. ...
- 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
- HDU 3308 LCIS 线段树区间更新
最近开始线段树一段时间了,也发现了不少大牛的博客比如HH大牛 ,小媛姐.这个题目是我在看HH大牛的线段树专题是给出的习题,(可以去他博客找找,真心推荐)原本例题是POJ3667 Hotel 这个题目 ...
- hdu4553(线段树)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4553 线段树功能:update:区间替换 query:询问满足条件的最左断点 分析:poj3667的加 ...
随机推荐
- 北京出dell s2740显示器 1900 - V2EX
水木社区归档站 北京出dell s2740显示器 1900 - V2EX 北京出dell s2740显示器 1900 By kekex · 6 小时 6 分钟前 · 188 次点击 购于今年4月份 镜 ...
- ALV 数值列负号前置 (EDIT_MASK应用)
1.建立自定义函数 浮点数显示FUNCTION conversion_exit_zsign_output.*"---------------------------------------- ...
- Python easy_insatll 安装包
Python 使用 easy_instal安装第三方扩展包更容易 easy insatll 下载地址 https://pypi.python.org/pypi/setuptools/ windows ...
- Servlet过滤器——创建过滤器
1.概述 介绍如何创建一个过滤器,并使用过滤器在打开页面的同时输出信息,此功能是由过滤器处理完成的. 2.技术要点 Serlvet过滤器实现了Filter接口,在Filter接口中定义了以下几个方法: ...
- 基于visual Studio2013解决面试题之0301累加
题目
- UVA 10795 - A Different Task(递归)
A Different Task The (Three peg) Tower of Hanoi problem is a popular one in computer science. Brie ...
- 与众不同 windows phone (9) - Push Notification(推送通知)之概述, 推送 Toast 通知
原文:与众不同 windows phone (9) - Push Notification(推送通知)之概述, 推送 Toast 通知 [索引页][源码下载] 与众不同 windows phone ( ...
- 设计模式 - 装饰者模式(Decorator Pattern) Java的IO类 用法
装饰者模式(Decorator Pattern) Java的IO类 用法 本文地址: http://blog.csdn.net/caroline_wendy/article/details/26716 ...
- 可能性dp+减少国家HDU4336
Card Collector Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ...
- Delphi调用C++导出的QT类
打开VS2008创建一个dll项目(创建了一个QT Library项目),新建头文件q4dapplication.h定义纯虚类: #ifndef Q4DAPPLICATION#define Q4DAP ...