题目链接: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. Kerberos的白银票据详解

    0x01白银票据(Silver Tickets)定义 白银票据(Silver Tickets)是伪造Kerberos票证授予服务(TGS)的票也称为服务票据.如下图所示,与域控制器没有AS-REQ 和 ...

  2. 【CF113D】Museum

    Portal --> cf113D Solution 额题意的话大概就是给一个无向图然后两个人给两个出发点,每个点每分钟有\(p[i]\)的概率停留,问这两个人在每个点相遇的概率是多少 如果说我 ...

  3. 《剑指offer》— JavaScript(14)链表中倒数第k个结点

    链表中倒数第k个结点 题目描述 输入一个链表,输出该链表中倒数第k个结点. 思路 两个指针,先让第一个指针和第二个指针都指向头结点,然后再让第一个指正走(k-1)步,到达第k个节点: 然后两个指针同时 ...

  4. Codeforces 480.E Parking Lot

    E. Parking Lot time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...

  5. 洛谷P1230 智力大冲浪

    题目描述 小伟报名参加中央电视台的智力大冲浪节目.本次挑战赛吸引了众多参赛者,主持人为了表彰大家的勇气,先奖励每个参赛者m元.先不要太高兴!因为这些钱还不一定都是你的?!接下来主持人宣布了比赛规则: ...

  6. Qt ------ 获取 wifi 信息

    QProcess:可以调用外部进程 netsh wlan show interfaces:可以查看连接哪个wifi netsh wlan show networks:显示所有可用的wifi netsh ...

  7. windows7中用vitualbox安装OS X 10.11 El Capitan 及 Xcode 7.0--转载

    在 Win 7或8 下使用 VirtualBOX 虚拟机安装 OS X 10.11 El Capitan 及 Xcode 7.0 来源:http://bbs.feng.com/read-htm-tid ...

  8. 前端PHP入门-005-爱情是常量还是变量

    常量 常--汉语字面为:长久,经久不变. 常量那就好翻译了:长久不变的值. 常量的使用范围非常广泛. 我们在以后,定义我们的工作目录.定义一些特点的帐户密码.版本号等我们都会使用到常量.所以这一块的知 ...

  9. [吴恩达机器学习笔记]12支持向量机1从逻辑回归到SVM/SVM的损失函数

    12.支持向量机 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考资料 斯坦福大学 2014 机器学习教程中文笔记 by 黄海广 12.1 SVM损失函数 从逻辑回归到支持向量机 为了描述 ...

  10. 封装-python

    六 封装 从封装本身的意思去理解,封装就好像是拿来一个麻袋,把小猫,小狗,小王八,还有alex一起装进麻袋,然后把麻袋封上口子.但其实这种理解相当片面 首先我们要了解 回到顶部 6.1 要封装什么 你 ...