POJ P3667 Hotel——solution
Description
The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, has named the Bullmoose Hotel on famed Cumberland Street as their vacation residence. This immense hotel has N (1 ≤ N ≤ 50,000) rooms all located on the same side of an extremely long hallway (all the better to see the lake, of course).
The cows and other visitors arrive in groups of size Di (1 ≤ Di ≤ N) and approach the front desk to check in. Each group i requests a set of Di contiguous rooms from Canmuu, the moose staffing the counter. He assigns them some set of consecutive room numbers r..r+Di-1 if they are available or, if no contiguous set of rooms is available, politely suggests alternate lodging. Canmuu always chooses the value of r to be the smallest possible.
Visitors also depart the hotel from groups of contiguous rooms. Checkout i has the parameters Xi and Di which specify the vacating of rooms Xi ..Xi +Di-1 (1 ≤ Xi ≤ N-Di+1). Some (or all) of those rooms might be empty before the checkout.
Your job is to assist Canmuu by processing M (1 ≤ M < 50,000) checkin/checkout requests. The hotel is initially unoccupied.
--by POJ
http://poj.org/problem?id=3667
给定初始值全0的区间[1,n],支持两种操作:
#include<cstdio>
using namespace std;
int n,m,L,R;
struct tree{
int lmax,rmax,max,lz;
}line[];
void builine(int ,int ,int );
void up(int ,int ,int );
void down(int ,int ,int );
int search(int ,int ,int ,int );
void change(int ,int ,int ,int );
int main()
{
int i,j,k,ans;
scanf("%d%d",&n,&m);
builine(,n,);
for(i=;i<=m;i++){
scanf("%d",&j);
if(j==){
scanf("%d",&k);
ans=search(,n,,k);
printf("%d\n",ans);
L=ans;R=L+k-;
if(L)
change(,n,,);
}
else{
scanf("%d%d",&L,&k);
R=L+k-;
change(,n,,);
}
}
}
void builine(int l,int r,int nu){
if(l==r){
line[nu].lmax=line[nu].rmax=line[nu].max=;
return ;
}
int mid=(l+r)>>;
builine(l,mid,nu<<);
builine(mid+,r,nu<<|);
line[nu].lmax=line[nu].rmax=line[nu].max=line[nu<<].max+line[nu<<|].max;
}
void up(int l,int r,int nu){
int mid=(l+r)>>;
if(line[nu<<].max>line[nu<<|].max)
line[nu].max=line[nu<<].max;
else
line[nu].max=line[nu<<|].max;
if(line[nu].max<line[nu<<].rmax+line[nu<<|].lmax)
line[nu].max=line[nu<<].rmax+line[nu<<|].lmax;
line[nu].lmax=line[nu<<].lmax==(mid-l+)?line[nu<<].lmax+line[nu<<|].lmax:line[nu<<].lmax;
line[nu].rmax=line[nu<<|].rmax==(r-mid)?line[nu<<|].rmax+line[nu<<].rmax:line[nu<<|].rmax;
}
void down(int l,int r,int nu){
int mid=(l+r)>>;
if(line[nu].lz){
line[nu<<].lmax=line[nu<<].max=line[nu<<].rmax=((line[nu].lz-)^)*(mid-l+);
line[nu<<|].lmax=line[nu<<|].max=line[nu<<|].rmax=((line[nu].lz-)^)*(r-mid);
line[nu<<].lz=line[nu<<|].lz=line[nu].lz;
line[nu].lz=;
}
}
int search(int l,int r,int nu,int len){
int mid=(l+r)>>,ans;
down(l,r,nu);
if(l==r)
return line[nu].max*l;
if(line[nu<<].max>=len){
ans=search(l,mid,nu<<,len);
return ans;
}
if(line[nu<<].rmax+line[nu<<|].lmax>=len){
ans=mid-line[nu<<].rmax+;
return ans;
}
if(line[nu<<|].max>=len){
ans=search(mid+,r,nu<<|,len);
return ans;
}
return ;
}
void change(int l,int r,int nu,int x){
if(L<=l&&r<=R){
line[nu].lmax=line[nu].rmax=line[nu].max=(r-l+)*(x^);
line[nu].lz=x+;
return ;
}
down(l,r,nu);
int mid=(l+r)>>;
if(L<=mid)
change(l,mid,nu<<,x);
if(R>mid)
change(mid+,r,nu<<|,x);
up(l,r,nu);
}
祝AC
POJ P3667 Hotel——solution的更多相关文章
- 线段树(区间合并) POJ 3667 Hotel
题目传送门 /* 题意:输入 1 a:询问是不是有连续长度为a的空房间,有的话住进最左边 输入 2 a b:将[a,a+b-1]的房间清空 线段树(区间合并):lsum[]统计从左端点起最长连续空房间 ...
- POJ 3667 Hotel(线段树)
POJ 3667 Hotel 题目链接 题意:有n个房间,如今有两个操作 1.找到连续长度a的空房间.入住,要尽量靠左边,假设有输出最左边的房间标号,假设没有输出0 2.清空[a, a + b - 1 ...
- poj 3667 Hotel (线段树)
http://poj.org/problem?id=3667 Hotel Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 94 ...
- POJ 3667 Hotel(线段树 区间合并)
Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 ...
- poj 3667 Hotel(线段树,区间合并)
Hotel Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 10858Accepted: 4691 Description The ...
- POJ 3667 Hotel (线段树区间合并)
题目链接:http://poj.org/problem?id=3667 最初给你n间空房,m个操作: 操作1 a 表示检查是否有连续的a间空房,输出最左边的空房编号,并入住a间房间. 操作2 a b ...
- (简单) POJ 3667 Hotel,线段树+区间合并。
Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...
- POJ 3667 Hotel(线段树+区间合并)
http://poj.org/problem?id=3667 题意: 有N个房间,M次操作.有两种操作(1)"1a",表示找到连续的长度为a的空房间,如果有多解,优先左边的,即表示 ...
- Poj 3667——hotel——————【线段树区间合并】
Hotel Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 13124 Accepted: 5664 Descriptio ...
随机推荐
- React 组件模式
简评:组件(component)是 React 的核心,了解它们有助于构建好的设计结构. 什么是组件(component) 组件运行你将 UI 拆分为独立的可重用的部分.和 JavaScript 函数 ...
- 初学struts2框架
昨天初学strts2,折腾了一晚上才正好一个简单的应用程序,在这个过程中遇到了很多的问题. 1. struts2的更新太快,所以从图书馆借的书常常会跟不上变化,所以有时执行起来会很麻烦. 2. 如果你 ...
- C#-WebForm-★★★LinQ-数据的条件组合查询并进行分页展示(未加各种限定)★★★
前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.as ...
- Vue中引入jquery方法
vue-cli webpack 引入jquery 今天费了一下午的劲,终于在vue-cli 生成的工程中引入了jquery,记录一下.(模板用的webpack) 首先在package.json里的 ...
- Angular Material 按钮图标系列
工做中经常用到Angular Material 中的好多按钮素材,奈何官网经常上不去,所以只能自己把这些常用的按钮扒下来了,留给自己同时也留给大家方便查看. Angular material mat- ...
- [性能测试]:关于消费类ISO8583协议脚本的开发
一,要发送的报文,转化成16进制的,报文如下 "\x01\x52"//报文长度338 "\x60\x00\x24\x00\x00"//TPDU "\x ...
- swagger注释API详细说明
API详细说明 注释汇总 @RequestMapping此注解的推荐配置 value method produces 示例: @ApiOperation("信息软删除") @Api ...
- Mac OS X中Launchpad的图标添加删除方法(添加方法别试了,和Linux很大区别)
说明:在Mac下的Launchpad图标添加和删除都与应用程序的app文件有关,如果单纯的只想在Launchpad添加自定义的图标,然后指定要某条命令运行时,建议不要这么干,Launchpad的图标管 ...
- win8.1中向IIS注册asp.net
以前都是用aspnet_regiis -I 命令向IIS注册asp.net ,今天换了win8.1后竟然发现这招不好使了. 根据提示,需要用dism.exe来完成注册. 折腾一会儿后,问题最终解决: ...
- Android多媒体技术之视频播放
1.Android中视频播放方式 surfaceView+MediaPlayer,通过MediaPlayer来控制视频的播放.暂停.进度等: 使用VideoView 来播放,这个类其实也是继承了Sur ...