HDU4553 约会安排
http://www.mamicode.com/info-detail-422707.html
线段树区间覆盖,开两个线段树,一个记录DS,一个NS
- // #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <sstream>
- #include <string>
- #include <algorithm>
- #include <list>
- #include <map>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <cmath>
- #include <cstdlib>
- #include <conio.h>
- using namespace std;
- #define clc(a,b) memset(a,b,sizeof(a))
- #define inf 0x3f3f3f3f
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- const int N = ;
- const int MOD = 1e9+;
- #define LL long long
- #define mi() (l+r)>>1
- double const pi = acos(-);
- void fre() {
- freopen("in.txt","r",stdin);
- }
- // inline int r() {
- // int x=0,f=1;char ch=getchar();
- // while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
- // while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
- // }
- struct Edge {
- int l,r;
- int lazy;
- int lm,rm,mm;
- } e1[N<<],e2[N<<];
- void pushdown(Edge e[],int rt) {
- if(e[rt].lazy!=-) {
- if(e[rt].lazy==) {
- e[rt<<].lm=e[rt<<].rm=e[rt<<].mm=e[rt<<].r-e[rt<<].l+;
- e[rt<<|].rm=e[rt<<|].lm=e[rt<<|].mm=e[rt<<|].r-e[rt<<|].l+;
- e[rt<<].lazy=e[rt<<|].lazy=;
- } else {
- e[rt<<].lm=e[rt<<].rm=e[rt<<].mm=;
- e[rt<<|].rm=e[rt<<|].lm=e[rt<<|].mm=;
- e[rt<<].lazy=e[rt<<|].lazy=;
- }
- e[rt].lazy=-;
- }
- }
- void pushup(Edge e[],int rt) {
- e[rt].lm=e[rt<<].lm;
- e[rt].rm=e[rt<<|].rm;
- if(e[rt<<].lm==e[rt<<].r-e[rt<<].l+) {
- e[rt].lm+=e[rt<<|].lm;
- }
- if(e[rt<<|].rm==e[rt<<|].r-e[rt<<|].l+) {
- e[rt].rm+=e[rt<<].rm;
- }
- e[rt].mm=max(max(e[rt<<].mm,e[rt<<|].mm),e[rt<<].rm+e[rt<<|].lm);
- }
- void build(int l,int r,int rt,Edge a[]) {
- a[rt].l=l;
- a[rt].r=r;
- a[rt].lm=a[rt].rm=a[rt].mm=(r-l+);
- a[rt].lazy=-;
- if(l==r)
- return;
- int mid=mi();
- build(lson,a);
- build(rson,a);
- }
- void update(Edge e[],int l,int r,int rt,int x) {
- if(e[rt].l==l&&e[rt].r==r) {
- if(x==) {
- e[rt].lm=e[rt].rm=e[rt].mm=r-l+;
- e[rt].lazy=;
- } else {
- e[rt].lm=e[rt].rm=e[rt].mm=;
- e[rt].lazy=;
- }
- return;
- }
- pushdown(e,rt);
- int mid=(e[rt].l+e[rt].r)>>;
- if(r<=mid) update(e,l,r,rt<<,x);
- else if(l>mid) update(e,l,r,rt<<|,x);
- else {
- update(e,l,mid,rt<<,x);
- update(e,mid+,r,rt<<|,x);
- }
- pushup(e,rt);
- }
- int query(Edge e[],int rt,int c) {
- if(e[rt].l==e[rt].r) {
- return e[rt].l;
- }
- pushdown(e,rt);
- int mid=(e[rt].l+e[rt].r)>>;
- if(e[rt<<].mm>=c) {
- return query(e,rt<<,c);
- } else if(e[rt<<].rm+e[rt<<|].lm>=c) {
- return mid-e[rt<<].rm+;
- } else {
- return query(e,rt<<|,c);
- }
- }
- int main() {
- // fre();
- int T;
- int cas=;
- cin>>T;
- while(T--) {
- printf("Case %d:\n",cas++);
- int n,q;
- cin>>n>>q;
- build(,n,,e1);//D
- build(,n,,e2);//N
- while(q--) {
- char s[];
- int x,y;
- scanf("%s",s);
- if(s[]=='S') {
- cin>>x>>y;
- update(e1,x,y,,);
- update(e2,x,y,,);
- printf("I am the hope of chinese chengxuyuan!!\n");
- } else if(s[]=='D') {
- cin>>x;
- if(e1[].mm<x) {
- printf("fly with yourself\n");
- } else {
- int s=query(e1,,x);
- printf("%d,let's fly\n",s);
- update(e1,s,s+x-,,);
- }
- } else {
- cin>>x;
- if(e1[].mm>=x) {
- int s=query(e1,,x);
- printf("%d,don't put my gezi\n",s);
- update(e1,s,s+x-,,);
- update(e2,s,s+x-,,);
- } else if(e2[].mm>=x) {
- int s=query(e2,,x);
- printf("%d,don't put my gezi\n",s);
- update(e1,s,s+x-,,);
- update(e2,s,s+x-,,);
- } else {
- printf("wait for me\n");
- }
- }
- }
- }
- return ;
- }
HDU4553 约会安排的更多相关文章
- hdu4553 约会安排 线段树
寒假来了,又到了小明和女神们约会的季节. 小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的大段发言后热情回复“呵呵”,所以,小明的最爱就是和女神们约会.与此同时,也有很多基友找他开黑,由于数量实 ...
- HDU-4553 约会安排(线段树维护连续区间)
http://acm.hdu.edu.cn/showproblem.php?pid=4553 Problem Description 寒假来了,又到了小明和女神们约会的季节. 小明虽为屌丝级码农,但 ...
- hdu4553约会安排 线段树
//DS QT 找一段最靠前的长度为QT的空间 //NS QT 找一段最靠前的长度为QT的空间.假设没找到能够将DS占领的空间当做空暇空间,找一段最靠前的空间 //STUDY!! L R 清空L ...
- hdu4553约会安排(线段树区间合并)
链接 poj3667的加强版 当时的题解 这里只不过对于女神需要另开算,DS的占用的时间不加在女神身上,女神的时间都要加,清空的时候也都要算. #include <iostream> #i ...
- hdu 4553 约会安排
约会安排 http://acm.hdu.edu.cn/showproblem.php?pid=4553 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu 4453 约会安排(线段树区间合并)
约会安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- E - Tunnel Warfare HDU - 1540 F - Hotel G - 约会安排 HDU - 4553 区间合并
E - Tunnel Warfare HDU - 1540 对这个题目的思考:首先我们已经意识到这个是一个线段树,要利用线段树来解决问题,但是怎么解决呢,这个摧毁和重建的操作都很简单,但是这个查询怎么 ...
- 约会安排---hdu4553(线段树,麻烦的区间覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4553 算是poj3667的加强版,建立两颗线段树,一个是DS区间,另一个是NS区间.那么根据题意, ...
- HDU - 4553 约会安排(区间合并)
https://cn.vjudge.net/problem/HDU-4553 Description 寒假来了,又到了小明和女神们约会的季节. 小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的 ...
随机推荐
- Python中的SET集合操作
python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和 ...
- python 编码问题(二)
>>> a = '中文' >>> chardet.detect(a) {'confidence': 0.7525, 'encoding': 'utf-8'} > ...
- shutdown -s -t
import java.io.*; import java.awt.*; public class HackDemo{ public static void main(String args[])th ...
- Eclipse项目和MyEclipse项目
因为Eclipse的项目结构和MyEclipse项目的结构不同,所以两者的项目之间不能直接运行的. 我们在创建Eclipse项目的时候可以进行一些设置,这样在Eclipse中创建的项目可以直接在MyE ...
- iOS:自定义工具栏、导航栏、标签栏
工具栏为UIToolBar,导航栏UINavigationBar,标签栏UITabBar.它们的样式基本上时差不多的,唯一的一点区别就是,工具栏一般需要自己去创建,然后添加到视图中,而导航栏和标签栏不 ...
- ASP.NET 数据绑定常用代码及其性能分析
用DataBinder.eval 绑定不必关心数据来源(Dataread或dataset).不必关心数据的类型eval会把这个数据对象转换为一个字符串.在底层绑定做了很多工作,使用了反射性能.正因为使 ...
- LA 3266 (贪心) Tian Ji -- The Horse Racing
题意: 田忌和齐王各有n匹马,如果马的速度比齐王的快就赢200,慢则输200,相等不赔不赚. 已知两人每匹马的速度(为整数)和齐王所排出的马的顺序,问田忌该如何应对才能使收益最大. 分析: 本以为是一 ...
- IIS6配置Asp.net MVC运行环境
Windows server 2003 + IIS6 搭建Asp.net MVC运行环境 1.安装.Net Framework4.0. 下载地址: http://www.microsoft.com/z ...
- Entity Framework查询,EF执行SQl
一.简介 EF 支持开放底层的 ADO.NET 框架,DbContext有三种常用方法 DbSet.SqlQuery //查询并返回Entities DbContext.Database.SqlQue ...
- 2013.11.15 初学ant构建
该做的事情都差不多做完了,今天开始用ant构建,所以学了下ant,其实要不是因为ubuntu时不时的抽风我应该早就可以开始构建了,但重写的时候也想清楚了一些逻辑,优化了一些地方.下面是我这辈子写的第一 ...