寒假来了,又到了小明和女神们约会的季节。
  小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的大段发言后热情回复“呵呵”,所以,小明的最爱就是和女神们约会。与此同时,也有很多基友找他开黑,由于数量实在过于巨大,怎么安排时间便成了小明的一大心事。
  我们已知小明一共有T的空闲时间,期间会有很多女神或者基友来找小明。
  作为一个操作系统曾经怒考71分的大神,小明想到了一个算法,即“首次适应算法”,根据操作系统课本的描述,就是找一段最靠前的符合要求的连续空间分配给每个请求,由此小明做出了一个决定:
  当一个基友来找小明时,小明就根据“首次适应算法”来找一段空闲的时间来和基友约好,如果找到,就说“X,let’s fly”(此处,X为开始时间),否则就说“fly with yourself”;
  当女神来找小明时,先使用一次“首次适应算法”,如果没有找到,小明就冒着木叽叽的风险无视所有屌丝基友的约定,再次使用“无视基友首次适应算法”,两次只要有一次找到,就说“X,don’t put my gezi”(此处,X为开始时间),否则就说“wait for me”
  当然,我们知道小明不是一个节操负无穷的人,如果和女神约会完,还有剩余时间,他还是会和原来约好的基友去dota的。(举个例子:小西(屌丝)和小明约好在1~5这个时间单位段内打dota,这时候,女神来和小明预约长度为3的时间段,那么最终就是1~3小明去和女神约会,搞定后在4~5和小西打dota)
  小明偶尔也会想要学习新知识,此时小明就会把某一个时间区间的所有已经预定的时间全部清空用来学习并且怒吼“I am the hope of chinese chengxuyuan!!”,不过小明一般都是三分钟热度,再有人来预定的话,小明就会按耐不住寂寞把学习新知识的时间分配出去。

记录区间最大段的空闲和区间最大段的和基友约的时间,lazy记录被占用或被清除

然后普通的线段树区间操作,分两种查询树上二分查询即可。

 #include<stdio.h>
#include<string.h>
const int maxm=;
const int INF=0x3f3f3f3f; int st[][maxm<<],stl[][maxm<<],str[][maxm<<],stx[][maxm<<];
int la[][maxm<<]; //-1 beizhanyong 1 beiqingchu
int sta;
//nvshen 0 diaosi 1 int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;} void build(int o,int l,int r){
st[][o]=st[][o]=stl[][o]=stl[][o]=str[][o]=str[][o]=r-l+;
stx[][o]=stx[][o]=l;
la[][o]=la[][o]=;
if(l==r)return;
int m=l+((r-l)>>);
build(o<<,l,m);
build(o<<|,m+,r);
} void pushup(int o,int l,int r,int t){
int m=l+((r-l)>>);
if(stl[t][o<<]==m-l+)stl[t][o]=stl[t][o<<]+stl[t][o<<|];
else stl[t][o]=stl[t][o<<];
if(str[t][o<<|]==r-m)str[t][o]=str[t][o<<]+str[t][o<<|];
else str[t][o]=str[t][o<<|];
if(st[t][o<<]>st[t][o<<|]){
st[t][o]=st[t][o<<];
stx[t][o]=stx[t][o<<];
}
else{
st[t][o]=st[t][o<<|];
stx[t][o]=stx[t][o<<|];
}
if(str[t][o<<]+stl[t][o<<|]>st[t][o]){
st[t][o]=str[t][o<<]+stl[t][o<<|];
stx[t][o]=m-str[t][o<<]+;
}
} void pushdown(int o,int l,int r,int t){
if(la[t][o]==-){
la[t][o<<]=la[t][o<<|]=-;
stl[t][o<<]=str[t][o<<]=stl[t][o<<|]=str[t][o<<|]=st[t][o<<]=st[t][o<<|]=;
stx[t][o<<]=stx[t][o<<|]=INF;
la[t][o]=;
}
else if(la[t][o]==){
la[t][o<<]=la[t][o<<|]=;
int m=l+((r-l)>>);
stl[t][o<<]=str[t][o<<]=st[t][o<<]=m-l+;
stl[t][o<<|]=str[t][o<<|]=st[t][o<<|]=r-m;
stx[t][o<<]=l;
stx[t][o<<|]=m+;
la[t][o]=;
}
} void query(int o,int l,int r,int c,int t){
if(st[t][o]>=c)sta=min(sta,stx[t][o]);
else return;
if(l==r)return;
pushdown(o,l,r,t);
int m=l+((r-l)>>);
if(str[t][o<<]+stl[t][o<<|]>=c&&m-str[t][o<<]+<sta)sta=m-str[t][o<<]+;
if(l<sta)query(o<<,l,m,c,t);
if(m+<sta)query(o<<|,m+,r,c,t);
} void update(int o,int l,int r,int ql,int qr,int c,int t){
if(ql<=l&&qr>=r){
if(c==-){
la[t][o]=-;
stl[t][o]=str[t][o]=st[t][o]=;
stx[t][o]=INF;
}
else if(c==){
la[t][o]=;
stl[t][o]=str[t][o]=st[t][o]=r-l+;
stx[t][o]=l;
}
return;
}
pushdown(o,l,r,t);
int m=l+((r-l)>>);
if(ql<=m)update(o<<,l,m,ql,qr,c,t);
if(qr>=m+)update(o<<|,m+,r,ql,qr,c,t);
pushup(o,l,r,t);
} char s[]; int main(){
int T;
scanf("%d",&T);
for(int q=;q<=T;++q){
int n,m;
scanf("%d%d",&n,&m);
printf("Case %d:\n",q);
build(,,n);
for(int i=;i<=m;++i){
scanf("%s",s);
if(s[]=='D'){
int c;
scanf("%d",&c);
sta=INF;
query(,,n,c,);
if(sta==INF)printf("fly with yourself\n");
else{
update(,,n,sta,sta+c-,-,);
printf("%d,let's fly\n",sta);
}
}
else if(s[]=='N'){
int c;
scanf("%d",&c);
sta=INF;
query(,,n,c,);
if(sta==INF){
query(,,n,c,);
if(sta==INF)printf("wait for me\n");
else{
update(,,n,sta,sta+c-,-,);
update(,,n,sta,sta+c-,-,);
printf("%d,don't put my gezi\n",sta);
}
}
else{
update(,,n,sta,sta+c-,-,);
update(,,n,sta,sta+c-,-,);
printf("%d,don't put my gezi\n",sta);
}
}
else if(s[]=='S'){
int a,b;
scanf("%d%d",&a,&b);
update(,,n,a,b,,);
update(,,n,a,b,,);
printf("I am the hope of chinese chengxuyuan!!\n");
}
}
}
}

hdu4553 约会安排 线段树的更多相关文章

  1. hdu4553约会安排 线段树

    //DS QT  找一段最靠前的长度为QT的空间 //NS QT  找一段最靠前的长度为QT的空间.假设没找到能够将DS占领的空间当做空暇空间,找一段最靠前的空间 //STUDY!! L R  清空L ...

  2. hdu4553约会安排(线段树区间合并)

    链接 poj3667的加强版 当时的题解 这里只不过对于女神需要另开算,DS的占用的时间不加在女神身上,女神的时间都要加,清空的时候也都要算. #include <iostream> #i ...

  3. hdu 4453 约会安排(线段树区间合并)

    约会安排 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  4. HDU-4553 约会安排(线段树维护连续区间)

    http://acm.hdu.edu.cn/showproblem.php?pid=4553 Problem Description 寒假来了,又到了小明和女神们约会的季节.  小明虽为屌丝级码农,但 ...

  5. HDU4553 约会安排

    http://www.mamicode.com/info-detail-422707.html 线段树区间覆盖,开两个线段树,一个记录DS,一个NS // #pragma comment(linker ...

  6. 约会安排---hdu4553(线段树,麻烦的区间覆盖)

      题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4553 算是poj3667的加强版,建立两颗线段树,一个是DS区间,另一个是NS区间.那么根据题意, ...

  7. HDU 4553 约会安排 (区间合并)【线段树】

    <题目链接> 寒假来了,又到了小明和女神们约会的季节.  小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的大段发言后热情回复“呵呵”,所以,小明的最爱就是和女神们约会.与此同时,也有 ...

  8. [Vani有约会]雨天的尾巴 线段树合并

    [Vani有约会]雨天的尾巴 LG传送门 线段树合并入门好题. 先别急着上线段树合并,考虑一下这题的暴力.一看就是树上差分,对于每一个节点统计每种救济粮的数量,再一遍dfs把差分的结果统计成答案.如果 ...

  9. P4556 [Vani有约会]雨天的尾巴(线段树合并+lca)

    P4556 [Vani有约会]雨天的尾巴 每个操作拆成4个进行树上差分,动态开点线段树维护每个点的操作. 离线处理完向上合并就好了 luogu倍增lca被卡了5分.....于是用rmq维护.... 常 ...

随机推荐

  1. js将接口返回的数据序列化

    <div style={{marginLeft: '80px'}}>                     <pre>                         {th ...

  2. Resharper插件的使用

    一.Resharper设置 1.1 智能提示 安装完毕后,IDE 的智能提示(Intellisense)便会默认使用 Resharper 的提示,不知道为什么,我一直不太喜欢它的提示.改过来,是在Op ...

  3. 遍历存储所有物体添加到列表中(使用GameObject.activeSelf进行判断)

    //存储菜单列表 List<GameObject> subMenu = new List<GameObject>(); //存储所有子菜单 public void StoreS ...

  4. @ResponseBody中文乱码解决方案

    java web项目,使用了springmvc4.0,用@ResponseBody返回中文字符串,乱码$$ 本以为很简单的问题,不过也找了一个小时. 网上有说这样配置的: <mvc:annota ...

  5. 使用RxSwift 实现登录页面的条件绑定

    我们在使用MVC建构进行开发时,对登录页面用户名密码等进行的处理一般是这样的,点击登录按钮判断用户框以及密码框输入的合法性,用一堆if真是屎一般!或者用textfield的代理来进行响应其实也是屎一般 ...

  6. :策略模式--Duck

    原则:封装变化的部分:针对超类编程,不针对实现:多组合少继承: #ifndef __DUCK_H__ #define __DUCK_H__ #include "FlyBehavior.h&q ...

  7. table-cell 布局

    table-cell能实现段落文字相对于div的垂直居中: 将div设置为display:table-cell; *display:inline-block;text-align:center; ve ...

  8. SUSE_LINUX 11 SP3 安装 IBM MQ 7.5

    0.环境介绍 mq7.5 suse linux 11 1. 上传安装包 上传安装包到 softWare/CI79IML.tar.gz 2. 安装证书 sh ./mqlicense.sh 输入 1 同意 ...

  9. E - Mahmoud and Ehab and the bipartiteness CodeForces - 862B (dfs黑白染色)

    Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipa ...

  10. POJ - 2823 Sliding Window (滑动窗口入门)

    An array of size n ≤ 10 6 is given to you. There is a sliding window of size kwhich is moving from t ...