题目链接: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. SAS数据步与过程步,数据步语句

    SAS数据步与过程步,数据步语句http://www.biostatistic.net/thread-2045-1-1.html  ---转载---原文作者:biostar(出处: 生物统计家园) 数 ...

  2. laravel5.1 使用中间表的多对多关联

    用户表user 标签表tag 中间表user_tag(user_id,tag_id) 在user模型中定义tags关联如下: public function tags() { return $this ...

  3. python析构函数

      class Test(object): def __init__(self, name): self.name = name print('这是构造函数') def say_hi(self): p ...

  4. python---Celery分布式任务队列了解

    linux下定时器了解 Celery 框架学习笔记(不错哟) Celery 分布式任务队列快速入门 Celery的最佳实践 一.Celery介绍 Celery 是一个 基于python开发的分布式异步 ...

  5. springboot项目启动成功后执行一段代码的两种方式

    springboot项目启动成功后执行一段代码的两种方式 实现ApplicationRunner接口 package com.lnjecit.lifecycle; import org.springf ...

  6. 使用$http.post()提交数据后台接收不到

    传参方式是request payload,参数格式是json,而并非用的是form传参,所以在后台用接收form数据的方式接收参数就接收不到了. POST表单请求提交时,使用的Content-Type ...

  7. svn常见错误

    1.svn提交报错:svn: Aborting commit:XXXXXremains in conflict 解决:说明Svn服务器上的对应内容,在你上次Update后已被别人修改了,而你也做了修改 ...

  8. redis-cluster 集群搭建详细指南及常见问题集合

    只当个搬运工吧 搭建篇:https://www.cnblogs.com/mafly/p/redis_cluster.html  测试能用 常见问题: 1 redis操作key时出现以下错误 (erro ...

  9. 详谈AngularJS的Directive

    指令Directive是AngularJS最重要的核心.我用AngularJS用的并不是很深,一直以来也是在使用中摸索,从一开始的什么都不懂,查不到系统的资料,到开始使用一些简单的数据绑定{{}},到 ...

  10. JS获取列表索引值

    html部分 <ul id="test"> <li>111</li> <li>222</li> <li>33 ...