约会安排---hdu4553(线段树,麻烦的区间覆盖)
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; #define INF 0xfffffff
#define N 110050
#define Lson r<<1
#define Rson r<<1|1 struct SegmentTree
{
int L, R;
bool ns, ds, study; ///0代表
int lsum[], rsum[], sum[]; ///0是屌丝,1女神; ///lsum区间左边(从L开始)连续最大不被覆盖的值
///rsum区间右边(到R介绍)连续最大不被覆盖的值
///sum整个区间连续最大不被覆盖的值 int Mid() { return (L+R)>>;}
int len() { return R-L+; } void clearPlan(bool x)///清空;
{
if(x)
{
lsum[] = lsum[] = len();
rsum[] = rsum[] = len();
sum[] = sum[] = len();
ns = ds = false; study = true;
}
} void NS(bool x)///女神;
{
if(x)
{
lsum[] = lsum[] = ;
rsum[] = rsum[] = ;
sum[] = sum[] = ;
ns = true; ds = false;
}
}
void DS(bool x)///屌丝;
{
if(x)
{
lsum[] = rsum[] = sum[] = ;
ds = true;
}
}
} a[N<<]; void Build(int r, int L, int R)
{
a[r].L = L, a[r].R = R;
a[r].clearPlan(true);///清空 ;
a[r].ns = a[r].ds = a[r].study = false; if(L == R)return ; Build(Lson, L, a[r].Mid());
Build(Rson, a[r].Mid()+, R);
} void Up(int r, int who)
{
if(a[r].L != a[r].R)
{
a[r].lsum[who] = a[Lson].lsum[who];
a[r].rsum[who] = a[Rson].rsum[who]; if(a[Lson].lsum[who] == a[Lson].len())
a[r].lsum[who] += a[Rson].lsum[who];
if(a[Rson].rsum[who] == a[Rson].len())
a[r].rsum[who] += a[Lson].rsum[who]; a[r].sum[who] = max(a[Lson].rsum[who] + a[Rson].lsum[who],
max(a[Lson].sum[who], a[Rson].sum[who]));
}
} void Down(int r)///这个顺序不能反
{
if(a[r].study)
{
a[Lson].clearPlan(true);
a[Rson].clearPlan(true);
a[r].study = false;
}
if(a[r].ns)
{
a[Lson].NS(true);
a[Rson].NS(true);
a[r].ns = a[r].ds = false;
}
if(a[r].ds)
{
a[Lson].DS(true);
a[Rson].DS(true);
a[r].ds = false;
}
} void Update(int r, int L, int R, int flag)
{
if(a[r].L == L && a[r].R == R)
{
if(flag == ) a[r].DS(true);
if(flag == ) a[r].NS(true);
if(flag == ) a[r].clearPlan(true); return;
} Down(r); if( R <= a[r].Mid())
Update(Lson, L, R, flag);
else if( L > a[r].Mid())
Update(Rson, L, R, flag);
else
{
Update(Lson, L, a[r].Mid(), flag);
Update(Rson, a[r].Mid()+, R, flag);
}
Up(r, );
Up(r, );
} int Query(int r, int num, int who)
{
Down(r); if(a[r].sum[who] < num) return ; if(a[r].lsum[who] >= num) return a[r].L;
if(a[Lson].sum[who] >= num) return Query(Lson, num, who); if(a[Lson].rsum[who]+a[Rson].lsum[who] >= num)
return a[Lson].R - a[Lson].rsum[who] + ;
return Query(Rson, num, who);
} int main()
{
int n, m, T, t = , R, L, time; scanf("%d", &T);
while(T--)
{
scanf("%d %d", &n, &m);
Build(, , n); printf("Case %d:\n", t++);
while(m--)
{
char s[];
scanf("%s", s);
if(s[] == 'D')
{
scanf("%d", &time);
L = Query(, time, );///屌丝是0; if( !L )printf("fly with yourself\n");
else
{
Update(, L, L+time-, );
printf("%d,let's fly\n", L);
}
}
else if(s[] == 'N')
{
scanf("%d", &time); L = Query(, time, );///先在屌丝时间里找;当在屌丝时间里没时间时在女神时间里找;
if( !L ) L = Query(, time, );///女神是1; if( !L )printf("wait for me\n");
else
{
Update(, L, L+time-, );
printf("%d,don't put my gezi\n", L);
}
}
else
{
scanf("%d %d", &L, &R);
Update(, L, R, );
printf("I am the hope of chinese chengxuyuan!!\n");
}
}
}
return ;
}
约会安排---hdu4553(线段树,麻烦的区间覆盖)的更多相关文章
- HDU-4553 约会安排(线段树维护连续区间)
http://acm.hdu.edu.cn/showproblem.php?pid=4553 Problem Description 寒假来了,又到了小明和女神们约会的季节. 小明虽为屌丝级码农,但 ...
- codeforces 652C C. Foe Pairs(尺取法+线段树查询一个区间覆盖线段)
题目链接: C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- HDU 4553 约会安排(线段树区间合并+双重标记)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4553 题目大意:就是有三种操作: ①DS x,安排一段长度为x的空闲时间跟屌丝一起,输出这段时间的起点 ...
- HDU 1754 I Hate It(线段树单点替换+区间最值)
I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...
- HDU 3577Fast Arrangement(线段树模板之区间增减更新 区间求和查询)
Fast Arrangement Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- POJ 3468 A Simple Problem with Integers(线段树模板之区间增减更新 区间求和查询)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 140120 ...
- POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)
POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...
- POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)
POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
随机推荐
- erlang-百度云推送Android服务端功能实现-erlang
百度云推送官方地址http://developer.baidu.com/wiki/index.php?title=docs/cplat/push 简单的介绍下原理: 百度云推送支持IOS和Androi ...
- [转]五分钟看懂UML类图与类的关系详解
在画类图的时候,理清类和类之间的关系是重点.类的关系有泛化(Generalization).实现(Realization).依赖(Dependency)和关联(Association).其中关联又分为 ...
- linux中,查看某个命令是来自哪个RPM包或者是通过哪个RPM包安装的
需求描述: 今天在测试ssh命令到底是哪个RPM包,安装之后生成的,找了一些文档 在这里进行记录下,主要是rpm -qf命令的使用,查询文件在哪个包里. 操作过程: 1.通过whereis 定位ssh ...
- C#读取Excel日期时间
//如果为20171219 if (dt.Rows[i][title].ToString().Trim().Length == 8) { realDate = dt.Rows[i][title].To ...
- mybatis由浅入深day01_5.3 Mapper动态代理方法
5.3 Mapper动态代理方法(程序员只需要写mapper接口(相当于dao接口)) 5.3.1 实现原理(mapper代理开发规范) 程序员还需要编写mapper.xml映射文件 程序员编写map ...
- Effective C++ Item 18 Make interfaces easy to use correctly and hard to use incorrectly
1. A good API will provide easy to use interfaces but also provide hard to miss-use interfaces. Usua ...
- /etc/hostname
我们可以使用 hostname 命令来修改主机名,但只是临时生效,如果想永久生效可以编辑 /etc/hostname 文件,注意不是每个 Linux 发行版都有该文件 root@Ubuntu_Lee: ...
- 实现类似printf这样的函数
来源:http://www.vimer.cn/2009/12/cc%E5%AE%9E%E7%8E%B0%E5%A4%9A%E5%8F%82%E6%95%B0%E5%87%BD%E6%95%B0%E7% ...
- ubuntu的两种网络连接模式
ubuntu的网络连接分成两种类型,一种是modern 模式, 这种模式的配置通过ifconfig命令来进行配置,重启之后失效,这种模式就是在destop 下右上角的网络连接.如图所示 modern模 ...
- LeetCode——Happy Number
Description: Write an algorithm to determine if a number is "happy". A happy number is a n ...