http://www.mamicode.com/info-detail-422707.html

线段树区间覆盖,开两个线段树,一个记录DS,一个NS

  1. // #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <sstream>
  6. #include <string>
  7. #include <algorithm>
  8. #include <list>
  9. #include <map>
  10. #include <vector>
  11. #include <queue>
  12. #include <stack>
  13. #include <cmath>
  14. #include <cstdlib>
  15. #include <conio.h>
  16. using namespace std;
  17. #define clc(a,b) memset(a,b,sizeof(a))
  18. #define inf 0x3f3f3f3f
  19. #define lson l,mid,rt<<1
  20. #define rson mid+1,r,rt<<1|1
  21. const int N = ;
  22. const int MOD = 1e9+;
  23. #define LL long long
  24. #define mi() (l+r)>>1
  25. double const pi = acos(-);
  26. void fre() {
  27. freopen("in.txt","r",stdin);
  28. }
  29. // inline int r() {
  30. // int x=0,f=1;char ch=getchar();
  31. // while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
  32. // while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
  33. // }
  34. struct Edge {
  35. int l,r;
  36. int lazy;
  37. int lm,rm,mm;
  38. } e1[N<<],e2[N<<];
  39.  
  40. void pushdown(Edge e[],int rt) {
  41. if(e[rt].lazy!=-) {
  42. if(e[rt].lazy==) {
  43. e[rt<<].lm=e[rt<<].rm=e[rt<<].mm=e[rt<<].r-e[rt<<].l+;
  44. e[rt<<|].rm=e[rt<<|].lm=e[rt<<|].mm=e[rt<<|].r-e[rt<<|].l+;
  45. e[rt<<].lazy=e[rt<<|].lazy=;
  46. } else {
  47. e[rt<<].lm=e[rt<<].rm=e[rt<<].mm=;
  48. e[rt<<|].rm=e[rt<<|].lm=e[rt<<|].mm=;
  49. e[rt<<].lazy=e[rt<<|].lazy=;
  50. }
  51. e[rt].lazy=-;
  52. }
  53. }
  54.  
  55. void pushup(Edge e[],int rt) {
  56. e[rt].lm=e[rt<<].lm;
  57. e[rt].rm=e[rt<<|].rm;
  58. if(e[rt<<].lm==e[rt<<].r-e[rt<<].l+) {
  59. e[rt].lm+=e[rt<<|].lm;
  60. }
  61. if(e[rt<<|].rm==e[rt<<|].r-e[rt<<|].l+) {
  62. e[rt].rm+=e[rt<<].rm;
  63. }
  64. e[rt].mm=max(max(e[rt<<].mm,e[rt<<|].mm),e[rt<<].rm+e[rt<<|].lm);
  65. }
  66. void build(int l,int r,int rt,Edge a[]) {
  67. a[rt].l=l;
  68. a[rt].r=r;
  69. a[rt].lm=a[rt].rm=a[rt].mm=(r-l+);
  70. a[rt].lazy=-;
  71. if(l==r)
  72. return;
  73. int mid=mi();
  74. build(lson,a);
  75. build(rson,a);
  76. }
  77.  
  78. void update(Edge e[],int l,int r,int rt,int x) {
  79. if(e[rt].l==l&&e[rt].r==r) {
  80. if(x==) {
  81. e[rt].lm=e[rt].rm=e[rt].mm=r-l+;
  82. e[rt].lazy=;
  83. } else {
  84. e[rt].lm=e[rt].rm=e[rt].mm=;
  85. e[rt].lazy=;
  86. }
  87. return;
  88. }
  89. pushdown(e,rt);
  90. int mid=(e[rt].l+e[rt].r)>>;
  91. if(r<=mid) update(e,l,r,rt<<,x);
  92. else if(l>mid) update(e,l,r,rt<<|,x);
  93. else {
  94. update(e,l,mid,rt<<,x);
  95. update(e,mid+,r,rt<<|,x);
  96. }
  97. pushup(e,rt);
  98. }
  99.  
  100. int query(Edge e[],int rt,int c) {
  101. if(e[rt].l==e[rt].r) {
  102. return e[rt].l;
  103. }
  104. pushdown(e,rt);
  105. int mid=(e[rt].l+e[rt].r)>>;
  106. if(e[rt<<].mm>=c) {
  107. return query(e,rt<<,c);
  108. } else if(e[rt<<].rm+e[rt<<|].lm>=c) {
  109. return mid-e[rt<<].rm+;
  110. } else {
  111. return query(e,rt<<|,c);
  112. }
  113. }
  114. int main() {
  115. // fre();
  116. int T;
  117. int cas=;
  118. cin>>T;
  119. while(T--) {
  120. printf("Case %d:\n",cas++);
  121. int n,q;
  122. cin>>n>>q;
  123. build(,n,,e1);//D
  124. build(,n,,e2);//N
  125. while(q--) {
  126. char s[];
  127. int x,y;
  128. scanf("%s",s);
  129. if(s[]=='S') {
  130. cin>>x>>y;
  131. update(e1,x,y,,);
  132. update(e2,x,y,,);
  133. printf("I am the hope of chinese chengxuyuan!!\n");
  134. } else if(s[]=='D') {
  135. cin>>x;
  136. if(e1[].mm<x) {
  137. printf("fly with yourself\n");
  138. } else {
  139. int s=query(e1,,x);
  140. printf("%d,let's fly\n",s);
  141. update(e1,s,s+x-,,);
  142. }
  143. } else {
  144. cin>>x;
  145. if(e1[].mm>=x) {
  146. int s=query(e1,,x);
  147. printf("%d,don't put my gezi\n",s);
  148. update(e1,s,s+x-,,);
  149. update(e2,s,s+x-,,);
  150. } else if(e2[].mm>=x) {
  151. int s=query(e2,,x);
  152. printf("%d,don't put my gezi\n",s);
  153. update(e1,s,s+x-,,);
  154. update(e2,s,s+x-,,);
  155. } else {
  156. printf("wait for me\n");
  157. }
  158. }
  159. }
  160. }
  161. return ;
  162. }

HDU4553 约会安排的更多相关文章

  1. hdu4553 约会安排 线段树

    寒假来了,又到了小明和女神们约会的季节. 小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的大段发言后热情回复“呵呵”,所以,小明的最爱就是和女神们约会.与此同时,也有很多基友找他开黑,由于数量实 ...

  2. HDU-4553 约会安排(线段树维护连续区间)

    http://acm.hdu.edu.cn/showproblem.php?pid=4553 Problem Description 寒假来了,又到了小明和女神们约会的季节.  小明虽为屌丝级码农,但 ...

  3. hdu4553约会安排 线段树

    //DS QT  找一段最靠前的长度为QT的空间 //NS QT  找一段最靠前的长度为QT的空间.假设没找到能够将DS占领的空间当做空暇空间,找一段最靠前的空间 //STUDY!! L R  清空L ...

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

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

  5. hdu 4553 约会安排

    约会安排 http://acm.hdu.edu.cn/showproblem.php?pid=4553 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  6. hdu 4453 约会安排(线段树区间合并)

    约会安排 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  7. E - Tunnel Warfare HDU - 1540 F - Hotel G - 约会安排 HDU - 4553 区间合并

    E - Tunnel Warfare HDU - 1540 对这个题目的思考:首先我们已经意识到这个是一个线段树,要利用线段树来解决问题,但是怎么解决呢,这个摧毁和重建的操作都很简单,但是这个查询怎么 ...

  8. 约会安排---hdu4553(线段树,麻烦的区间覆盖)

      题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4553 算是poj3667的加强版,建立两颗线段树,一个是DS区间,另一个是NS区间.那么根据题意, ...

  9. HDU - 4553 约会安排(区间合并)

    https://cn.vjudge.net/problem/HDU-4553 Description 寒假来了,又到了小明和女神们约会的季节.  小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的 ...

随机推荐

  1. Python中的SET集合操作

    python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和 ...

  2. python 编码问题(二)

    >>> a = '中文' >>> chardet.detect(a) {'confidence': 0.7525, 'encoding': 'utf-8'} > ...

  3. shutdown -s -t

    import java.io.*; import java.awt.*; public class HackDemo{ public static void main(String args[])th ...

  4. Eclipse项目和MyEclipse项目

    因为Eclipse的项目结构和MyEclipse项目的结构不同,所以两者的项目之间不能直接运行的. 我们在创建Eclipse项目的时候可以进行一些设置,这样在Eclipse中创建的项目可以直接在MyE ...

  5. iOS:自定义工具栏、导航栏、标签栏

    工具栏为UIToolBar,导航栏UINavigationBar,标签栏UITabBar.它们的样式基本上时差不多的,唯一的一点区别就是,工具栏一般需要自己去创建,然后添加到视图中,而导航栏和标签栏不 ...

  6. ASP.NET 数据绑定常用代码及其性能分析

    用DataBinder.eval 绑定不必关心数据来源(Dataread或dataset).不必关心数据的类型eval会把这个数据对象转换为一个字符串.在底层绑定做了很多工作,使用了反射性能.正因为使 ...

  7. LA 3266 (贪心) Tian Ji -- The Horse Racing

    题意: 田忌和齐王各有n匹马,如果马的速度比齐王的快就赢200,慢则输200,相等不赔不赚. 已知两人每匹马的速度(为整数)和齐王所排出的马的顺序,问田忌该如何应对才能使收益最大. 分析: 本以为是一 ...

  8. IIS6配置Asp.net MVC运行环境

    Windows server 2003 + IIS6 搭建Asp.net MVC运行环境 1.安装.Net Framework4.0. 下载地址: http://www.microsoft.com/z ...

  9. Entity Framework查询,EF执行SQl

    一.简介 EF 支持开放底层的 ADO.NET 框架,DbContext有三种常用方法 DbSet.SqlQuery //查询并返回Entities DbContext.Database.SqlQue ...

  10. 2013.11.15 初学ant构建

    该做的事情都差不多做完了,今天开始用ant构建,所以学了下ant,其实要不是因为ubuntu时不时的抽风我应该早就可以开始构建了,但重写的时候也想清楚了一些逻辑,优化了一些地方.下面是我这辈子写的第一 ...