约会安排

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 433    Accepted Submission(s): 145

Problem Description
  寒假来了,又到了小明和女神们约会的季节。
  小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的大段发言后热情回复“呵呵”,所以,小明的最爱就是和女神们约会。与此同时,也有很多基友找他开黑,由于数量实在过于巨大,怎么安排时间便成了小明的一大心事。
  我们已知小明一共有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!!”,不过小明一般都是三分钟热度,再有人来预定的话,小明就会按耐不住寂寞把学习新知识的时间分配出去。
 
Input
输入第一行为CASE,表示有CASE组测试数据;
每组数据以两个整数T,N开始,T代表总共的时间,N表示预约请求的个数;
接着的N行,每行表示一个女神或者基友的预约,“NS QT”代表一个女神来找小明约一段长为QT的时间,“DS QT”则代表一个屌丝的长为QT的请求,当然也有可能是小明想学知识了,“STUDY!! L R”代表清空L~R区间内的所有请求。

[Technical Specification]
1. 1 <= CASE <= 30
2. 1 <= T, N <= 100000
3. 1 <= QT <= 110000
4. 1 <= L <= R <=T

 
Output
对于每一个case,第一行先输出“Case C:”代表是第几个case,然后N行,每行对应一个请求的结果(参照描述)。
输出样本(可复制此处):
“X,let's fly”,”fly with yourself”,”X,don't put my gezi”,”wait for me”,”I am the hope of chinese chengxuyuan!!”
 
Sample Input
1
5 6
DS 3
NS 2
NS 4
STUDY!! 1 5
DS 4
NS 2
 
Sample Output
Case 1:
1,let's fly
4,don't put my gezi
wait for me
I am the hope of chinese chengxuyuan!!
1,let's fly
1,don't put my gezi

找最左边连续大于x的空间的位置。。

对于一个区间:

符合条件的这个位置要么在最左, 最右, 要么跨越该区间中点 。

否则就递归到左右子区间,并且符合上面的条件。

开一个LL[rt] , RR[rt] 表示区间最左边有多少个空位,最右边有多少连续空位。

就可以维护出来 。

对于题目要开两颗线段树, 一棵是DS+NS的, 一颗是NS的 。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
using namespace std;
typedef pair<int,int> pii ;
#define X first
#define Y second
#define root 1,n,1
#define lr rt<<1
#define rr rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int mod = ;
int n , m ;
int lazy[N<<][] , LL[N<<][] , RR[N<<][] , ms[N<<][]; int s , x , y ; void build( int l , int r , int rt ) {
for( int i = ; i < ; ++i ){
ms[rt][i] = LL[rt][i] = RR[rt][i] = r-l+; // rest from left and right
lazy[rt][i] = ; // the state of pushdown
}
if( l == r ) return ;
int mid = (l+r)>>;
build(lson),build(rson);
} void Up( int l , int r , int rt , int i ) {
int mid = (l+r)>>;
ms[rt][i] = max( max( ms[lr][i] , ms[rr][i] ) , RR[lr][i] + LL[rr][i] ) ;
LL[rt][i] = LL[lr][i] ;
if( LL[lr][i] == mid - l + ) LL[rt][i] += LL[rr][i];
RR[rt][i] = RR[rr][i];
if( RR[rr][i] == r - mid ) RR[rt][i] += RR[lr][i];
} void Down( int l , int r , int rt , int i )
{
if( l == r ) return ;
int mid = (l+r)>> ;
if( lazy[rt][i] == ) {
lazy[lr][i] = lazy[rr][i] = ;
ms[lr][i] = ms[rr][i] = ;
LL[lr][i] = RR[lr][i] = ;
LL[rr][i] = RR[rr][i] = ;
}
if( lazy[rt][i] == - ) {
lazy[lr][i] = lazy[rr][i] = - ;
ms[lr][i] = mid - l + ;
ms[rr][i] = r - mid ;
LL[lr][i] = RR[lr][i] = mid - l + ;
LL[rr][i] = RR[rr][i] = r - mid ;
}
lazy[rt][i] = ;
} void relax( int& a , int b ) {
if( a == - ) a = b ;
else a=(a<b?a:b);
}
void query( int l , int r , int rt , int x , int i ) {
if( ms[rt][i] < x ) return ;
int mid = (l+r)>>;
if( l == r ) {
if( LL[rt][i] == && x == ) relax(s,l) ;
return ;
}
else {
Down(l,r,rt,i);
if( LL[rt][i] >= x ) relax(s,l) ;
if( RR[lr][i] + LL[rr][i] >= x ) relax( s , mid - RR[lr][i] + );
if( RR[rt][i] >= x ) relax(s,r-RR[rt][i]+);
}
query(lson,x,i) , query(rson,x,i);
Up(l,r,rt,i);
} void update( int l , int r , int rt , int L , int R , int i ) { if( l == L && r == R ) {
ms[rt][i] = LL[rt][i] = RR[rt][i] = ;
lazy[rt][i] = ;
return ;
}
Down( l , r , rt ,i ) ;
int mid = (l+r)>>;
if( R <= mid ) update(lson,L,R,i);
else if( L > mid ) update(rson,L,R,i);
else update(lson,L,mid,i) , update(rson,mid+,R,i);
Up(l,r,rt,i);
} void clean( int l , int r , int rt , int L , int R ) {
if( l == L && r == R ) {
for( int i = ; i < ; ++i ) {
LL[rt][i] = RR[rt][i] = ms[rt][i] = r - l + ;
lazy[rt][i] = - ;
}
return ;
}
Down(l,r,rt,); Down(l,r,rt,);
int mid = (l+r)>>;
if( R <= mid ) clean(lson,L,R);
else if( L > mid ) clean(rson,L,R);
else clean(lson,L,mid) , clean(rson,mid+,R);
Up(l,r,rt,); Up(l,r,rt,);
} int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // LOCAL
int _ , cas = ; char op[];
scanf("%d",&_);
while( _-- ) {
printf("Case %d:\n",cas++);
scanf("%d%d",&n,&m);
build(root);
while( m-- ) {
scanf("%s",op);
s = - ;
if( op[] == 'D' ) {
scanf("%d",&x);
query(root,x,);
if( s == - ) puts("fly with yourself");
else {
printf("%d,let's fly\n",s);
update(root,s,s+x-,);
}
}
else if( op[] == 'N' ) {
scanf("%d",&x);
query( root , x , );
if( s == - ) {
query( root , x , );
if( s == - ) puts("wait for me");
else {
printf("%d,don't put my gezi\n",s);
update(root,s,s+x-,);
update(root,s,s+x-,);
}
}
else {
printf("%d,don't put my gezi\n",s);
update(root,s,s+x-,);
update(root,s,s+x-,);
}
}
else {
scanf("%d%d",&x,&y);
puts("I am the hope of chinese chengxuyuan!!");
clean( root , x , y );
}
}
}
}

hdu 4453 约会安排(线段树区间合并)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. hdu 1540 Tunnel Warfare 线段树 区间合并

    题意: 三个操作符 D x:摧毁第x个隧道 R x:修复上一个被摧毁的隧道,将摧毁的隧道入栈,修复就出栈 Q x:查询x所在的最长未摧毁隧道的区间长度. 1.如果当前区间全是未摧毁隧道,返回长度 2. ...

  9. HDU 4351 Digital root 线段树区间合并

    依然不是十分理解……待考虑…… #include <cstdio> #include <cstring> #include <cstdlib> #include & ...

随机推荐

  1. 联想ideapad 310s如何进BIOS,换固态硬盘SSD,配置U盘启动,重装Win10系统

    1. 如何进BIOS 关机情况下,捅一下Novo键,即可进入BIOS 2. 安装固态硬盘 Ideadpad 310S 本身自带的硬盘是5400转的机械硬盘,容量小速度慢.换的新的固态硬盘是SATA接口 ...

  2. Oracle单引号转义符

    作用:Increase readability and usability (增加可读性和可用性) 用法:select  q'[ select * from ]'||table_name|| ';'  ...

  3. spring boot generator

    pom.xml 插件引用依赖 <build> <plugins> <plugin> <groupId>org.springframework.boot& ...

  4. php内置函数分析之strtoupper()、strtolower()

    strtoupper(): PHP_FUNCTION(strtoupper) { zend_string *str; ZEND_PARSE_PARAMETERS_START(, ) Z_PARAM_S ...

  5. mysql order by 自定义

    TIMESTAMPDIFF 语法: TIMESTAMPDIFF(interval,datetime_expr1,datetime_expr2). 说明: 返回日期或日期时间表达式datetime_ex ...

  6. Python---字符串拼接和严格字符串

    BIF内建函数 Python3中提供了多少个内置函数     68 Python3中TUling tuling是不是一样的   严格区别大小 “=”和“==”的运用与区别 - ‘=‘ 是用来赋值的 - ...

  7. Conda 中安装 Keras

    conda create -n keras python=3.5 ipykernel activate keras python -m ipykernel install --user --name ...

  8. handy源码阅读(二):EventsImp类

    EventsImp用于完成事件的处理. class EventsImp { EventBase* base_; PollerBase* poller_; std::atomic<bool> ...

  9. Selenium-Switch与SelectApi介绍

    Switch 我们在UI自动化测试时,总会出现新建一个tab页面,弹出一个浏览器级别的弹框或者是出现一个iframe标签,这时我们用WebDriver提供的Api接口就无法处理这些情况了.需要用到Se ...

  10. Nginx实现反向代理与负载均衡

    1.什么是反向代理 使用nginx实现反向代理,Nginx只做请求的转发,后台有多个http服务器提供服务,nginx的功能就是把请求转发给后面的服务器,决定把请求转发给谁. 2.在一个虚拟机上创建两 ...