题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4553

题目大意:就是有三种操作:

     ①DS x,安排一段长度为x的空闲时间跟屌丝一起,输出这段时间的起点,若没有则输出“fly with yourself”。

     ②NS x,安排一段长度为x的空闲时间跟女神在一起,若没有则可以无视屌丝的时间再找一次,输出这段时间的起点,若两次都没有则输出“wait for me”。

     ③STUDY!! l r,清空l~r这段时间的所有安排。

解题思路:区间合并问题,但是要分为屌丝、女神两种标记,就是每种操作基本都要来双份代码变长了。。。找一段空闲时间的起点一开始不会的,后来学习了一下。其他的没什么要特别注意的地方。

代码:

 #include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<string>
#define LC(a) (a<<1)
#define RC(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int N=1e5+; struct node{
int l,r;
int dls,dms,drs;//屌丝
int nls,nms,nrs;//女神
}tree[N<<]; int x; void pushup(int p){
//屌丝
if(tree[LC(p)].dls==tree[LC(p)].r-tree[LC(p)].l+)
tree[p].dls=tree[LC(p)].dls+tree[RC(p)].dls;
else
tree[p].dls=tree[LC(p)].dls;
if(tree[RC(p)].drs==tree[RC(p)].r-tree[RC(p)].l+)
tree[p].drs=tree[RC(p)].drs+tree[LC(p)].drs;
else
tree[p].drs=tree[RC(p)].drs;
tree[p].dms=max(tree[LC(p)].drs+tree[RC(p)].dls,max(tree[LC(p)].dms,tree[RC(p)].dms));
//女神
if(tree[LC(p)].nls==tree[LC(p)].r-tree[LC(p)].l+)
tree[p].nls=tree[LC(p)].nls+tree[RC(p)].nls;
else
tree[p].nls=tree[LC(p)].nls;
if(tree[RC(p)].nrs==tree[RC(p)].r-tree[RC(p)].l+)
tree[p].nrs=tree[RC(p)].nrs+tree[LC(p)].nrs;
else
tree[p].nrs=tree[RC(p)].nrs;
tree[p].nms=max(tree[LC(p)].nrs+tree[RC(p)].nls,max(tree[LC(p)].nms,tree[RC(p)].nms));
} void pushdown(int p){
//屌丝
if(tree[p].dms==tree[p].r-tree[p].l+){
tree[LC(p)].dls=tree[LC(p)].dms=tree[LC(p)].drs=tree[LC(p)].r-tree[LC(p)].l+;
tree[RC(p)].dls=tree[RC(p)].dms=tree[RC(p)].drs=tree[RC(p)].r-tree[RC(p)].l+;
}
else if(tree[p].dms==){
tree[LC(p)].dls=tree[LC(p)].dms=tree[LC(p)].drs=;
tree[RC(p)].dls=tree[RC(p)].dms=tree[RC(p)].drs=;
}
//女神
if(tree[p].nms==tree[p].r-tree[p].l+){
tree[LC(p)].nls=tree[LC(p)].nms=tree[LC(p)].nrs=tree[LC(p)].r-tree[LC(p)].l+;
tree[RC(p)].nls=tree[RC(p)].nms=tree[RC(p)].nrs=tree[RC(p)].r-tree[RC(p)].l+;
}
else if(tree[p].nms==){
tree[LC(p)].nls=tree[LC(p)].nms=tree[LC(p)].nrs=;
tree[RC(p)].nls=tree[RC(p)].nms=tree[RC(p)].nrs=;
}
} void build(int p,int l,int r){
tree[p].l=l;
tree[p].r=r;
if(l==r){
tree[p].dls=tree[p].dms=tree[p].drs=tree[p].nls=tree[p].nms=tree[p].nrs=;
return;
}
build(LC(p),l,MID(l,r));
build(RC(p),MID(l,r)+,r);
pushup(p);
} void update(int p,int l,int r,int op){
if(l>tree[p].r||r<tree[p].l)
return;
if(l<=tree[p].l&&r>=tree[p].r){
if(op==)
tree[p].dls=tree[p].dms=tree[p].drs=;
else if(op==)
tree[p].nls=tree[p].nms=tree[p].nrs=;
else
tree[p].dls=tree[p].dms=tree[p].drs=tree[p].nls=tree[p].nms=tree[p].nrs=tree[p].r-tree[p].l+;
return;
}
pushdown(p);
update(LC(p),l,r,op);
update(RC(p),l,r,op);
pushup(p);
} int query(int p,int l,int r,char op){
//这句一定要加,否则当所需时间为1时,可能会陷入无限递归
if(l==r)
return l;
pushdown(p);
if(op=='D'){
if(tree[LC(p)].dms>=x)
return query(LC(p),l,MID(l,r),op);
else if(tree[LC(p)].drs+tree[RC(p)].dls>=x){
int t=tree[LC(p)].r-tree[LC(p)].drs+;
return t;
}
else
return query(RC(p),MID(l,r)+,r,op);
}
else{
if(tree[LC(p)].nms>=x)
return query(LC(p),l,MID(l,r),op);
else if(tree[LC(p)].nrs+tree[RC(p)].nls>=x){
int t=tree[LC(p)].r-tree[LC(p)].nrs+;
return t;
}
else
return query(RC(p),MID(l,r)+,r,op);
}
pushup(p);
} int main(){
int T;
scanf("%d",&T);
int cas=;
while(T--){
int n,q;
scanf("%d%d",&n,&q);
build(,,n);
printf("Case %d:\n",++cas);
while(q--){
char op[];
scanf("%s",op);
if(op[]=='D'){
scanf("%d",&x);
if(tree[].dms>=x){
int l=query(,,n,'D');
update(,l,l+x-,);
printf("%d,let's fly\n",l);
}
else
puts("fly with yourself");
}
else if(op[]=='N'){
scanf("%d",&x);
int l;
if(tree[].dms>=x){
l=query(,,n,'D');
//把屌丝和女神的这段时间都安排上,因为无论对屌丝还是女神来说这段时间都被安排了。
update(,l,l+x-,);
update(,l,l+x-,);
printf("%d,don't put my gezi\n",l);
}
else if(tree[].nms>=x){
l=query(,,n,'N');
update(,l,l+x-,);
update(,l,l+x-,);
printf("%d,don't put my gezi\n",l);
}
else
puts("wait for me");
}
else{
int l,r;
scanf("%d%d",&l,&r);
update(,l,r,);
puts("I am the hope of chinese chengxuyuan!!");
}
}
}
return ;
}

HDU 4553 约会安排(线段树区间合并+双重标记)的更多相关文章

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

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

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

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

  3. HDU 6638 - Snowy Smile 线段树区间合并+暴力枚举

    HDU 6638 - Snowy Smile 题意 给你\(n\)个点的坐标\((x,\ y)\)和对应的权值\(w\),让你找到一个矩形,使这个矩阵里面点的权值总和最大. 思路 先离散化纵坐标\(y ...

  4. hdu 3397 Sequence operation (线段树 区间合并 多重标记)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=3397 题意: 给你一串01串,有5种操作 0. 区间全部变为0 1.区间全部变为1 2.区间异或 3.询问 ...

  5. HDU 5316——Magician——————【线段树区间合并区间最值】

    Magician Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  6. HDU 3911 Black And White (线段树区间合并 + lazy标记)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3911 给你n个数0和1,m个操作: 0操作  输出l到r之间最长的连续1的个数 1操作  将l到r之间 ...

  7. HDU 1540 Tunnel Warfare 线段树区间合并

    Tunnel Warfare 题意:D代表破坏村庄,R代表修复最后被破坏的那个村庄,Q代表询问包括x在内的最大连续区间是多少 思路:一个节点的最大连续区间由(左儿子的最大的连续区间,右儿子的最大连续区 ...

  8. (简单) HDU 3308 LCIS,线段树+区间合并。

    Problem Description Given n integers. You have two operations: U A B: replace the Ath number by B. ( ...

  9. hdu 3308 LCIS(线段树区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=3308 LCIS Time Limit: 6000/2000 MS (Java/Others)     ...

随机推荐

  1. 【CF331E】Biologist(网络流,最小割)

    [CF331E]Biologist(网络流,最小割) 题面 洛谷 翻译: 有一个长度为\(n\)的\(01\)串,将第\(i\)个位置变为另外一个数字的代价是\(v_i\). 有\(m\)个要求 每个 ...

  2. BZOJ2716:[Violet 3]天使玩偶——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2716 样例输入 2 31 12 32 1 21 3 32 4 2 样例输出 1 2 ———————— ...

  3. python基础----元类metaclass

    1 引子 class Foo: pass f1=Foo() #f1是通过Foo类实例化的对象 python中一切皆是对象,类本身也是一个对象,当使用关键字class的时候,python解释器在加载cl ...

  4. 我的emacs简易配置

    ;;------------语言环境字符集设置(utf-8)------------- (set-language-environment 'Chinese-GB) (set-keyboard-cod ...

  5. [vim]乱码问题

    在vim输入中文乱码 1. 检查系统是否支持中文 locale -a 没有中文支持 安装中文包 apt-get install language-pack-zh-hans -y 2.这样可以输入中文了 ...

  6. 题解【luogu3709 大爷的字符串题】

    Description 个人觉得这是这道题最难的一步...出题人的语文... 每次给出一个区间,求这个区间最少能被多少个单调上升的序列覆盖. Solution 这个东西可以转化为这个区间中出现次数最多 ...

  7. 修改Docker默认镜像和容器的存储位置

    一.Why Docker默认的镜像和容器存储位置在/var/lib/docker中,如果仅仅是做测试,我们可能没有必要修改,但是当大量使用的时候,我们可能就要默认存储的位置了. 二.How 2.1 修 ...

  8. springboot+spring session+redis+nginx实现session共享和负载均衡

    环境 centos7. jdk1.8.nginx.redis.springboot 1.5.8.RELEASE session共享 添加spring session和redis依赖 <depen ...

  9. JS事件大全及兼容

    一般事件 事件 浏览器支持 描述 onClick IE3|N2|O3 鼠标点击事件,多用在某个对象控制的范围内的鼠标点击 onDblClick IE4|N4|O 鼠标双击事件 onMouseDown  ...

  10. SSM框架使用-wrong

    mybatis手册 1. mybatis 绑定错误 如果出现: org.apache.ibatis.binding.BindingException: Invalid bound statement ...