http://blog.csdn.net/niuox/article/details/9664487

这道题明显是线段树,根据题意可以知道:

(用0和1表示是否包含区间,-1表示该区间内既有包含又有不包含)

U:把区间[l,r]覆盖成1

I:把[-∞,l)(r,∞]覆盖成0

D:把区间[l,r]覆盖成0

C:把[-∞,l)(r,∞]覆盖成0 , 且[l,r]区间0/1互换

S:[l,r]区间0/1互换

这里有两个地方和区间更新不一样

一个是会更新选中区间以外的所有区域,可以这样子解决:

  1. void update(char val,int L,int R,int l,int r,int rt)
  2. {
  3. ...
  4. int mid = (l + r)>>;
  5. if (L <= mid)
  6. {
  7. update(val,L,R,l,mid,rt<<);
  8. }
  9. else if(val == 'I' || val == 'C')
  10. {
  11. a[rt<<] = col[rt<<] = ;
  12. }
  13. if(R > mid)
  14. {
  15. update(val,L,R,mid+,r,rt<<|);
  16. }
  17. else if(val == 'I' || val == 'C')
  18. {
  19. a[rt<<|] = col[rt<<|] = ;
  20. }
  21. }

if判断左边是否小于mid,如果不是,那么更新它的左边就是我们想要的选中区域外了,右边同理。

第二个是有两种更新方式,覆盖和异或

这种问题一般需要两种标记,但这里其中一种是覆盖,所以一种标记可以用值自身表示,-1表示杂,非-1表示纯。一个标记数组就行。

然后还要理清两种标记使用的方式

很明显我们可以知道这个性质:

当一个区间被覆盖后,不管之前有没有异或标记都没有意义了
所以当一个节点得到覆盖标记时把异或标记清空

第三种是开闭区间,这里可以通过把所有数乘2处理(偶数表示端点,奇数表示两端点间的区间)。

  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cstdio>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <stack>
  9. #include <queue>
  10. #include <cctype>
  11. #include <vector>
  12. #include <iterator>
  13. #include <set>
  14. #include <map>
  15. #include <sstream>
  16. using namespace std;
  17.  
  18. #define mem(a,b) memset(a,b,sizeof(a))
  19. #define pf printf
  20. #define sf scanf
  21. #define spf sprintf
  22. #define pb push_back
  23. #define debug printf("!\n")
  24. #define MAXN 65535*2
  25. #define MAX(a,b) a>b?a:b
  26. #define blank pf("\n")
  27. #define LL long long
  28. #define ALL(x) x.begin(),x.end()
  29. #define INS(x) inserter(x,x.begin())
  30. #define pqueue priority_queue
  31. #define INF 0x3f3f3f3f
  32.  
  33. int n,m;
  34.  
  35. int a[MAXN<<],col[MAXN<<],ans;
  36.  
  37. bool vis[MAXN];
  38.  
  39. void FXOR(int x)
  40. {
  41. if(a[x]!=-) a[x]^=;
  42. else col[x]^=;
  43. }
  44.  
  45. void PushDown(int rt)
  46. {
  47. if(a[rt] != -)
  48. {
  49. a[rt<<] = a[rt<<|] = a[rt];
  50. col[rt<<] = col[rt<<|] = ;
  51. a[rt] = -;
  52. }
  53. if(col[rt])
  54. {
  55. FXOR(rt<<);
  56. FXOR(rt<<|);
  57. col[rt] = ;
  58. }
  59. }
  60.  
  61. void update(char val,int L,int R,int l,int r,int rt)
  62. {
  63. if(L <= l && r <= R)
  64. {
  65. if(val == 'U')
  66. {
  67. a[rt] = ;
  68. col[rt] = ;
  69. }
  70. else if(val == 'D')
  71. {
  72. a[rt] = col[rt] = ;
  73. }
  74. else if(val == 'C' || val == 'S')
  75. {
  76. FXOR(rt);
  77. }
  78. return;
  79. }
  80. PushDown(rt);
  81. int mid = (l + r)>>;
  82. if (L <= mid)
  83. {
  84. update(val,L,R,l,mid,rt<<);
  85. }
  86. else if(val == 'I' || val == 'C')
  87. {
  88. a[rt<<] = col[rt<<] = ;
  89. }
  90. if(R > mid)
  91. {
  92. update(val,L,R,mid+,r,rt<<|);
  93. }
  94. else if(val == 'I' || val == 'C')
  95. {
  96. a[rt<<|] = col[rt<<|] = ;
  97. }
  98. }
  99.  
  100. void query(int l,int r,int rt)
  101. {
  102. if(a[rt] == )
  103. {
  104. for(int i = l;i<=r;i++) vis[i] = true;
  105. return;
  106. }
  107. else if(a[rt] == ) return;
  108. if(l == r) return;
  109. PushDown(rt);
  110. int mid = (l + r)>>;
  111. query(l,mid,rt<<);
  112. query(mid+,r,rt<<|);
  113. }
  114.  
  115. int main()
  116. {
  117. int r,t;
  118. char op,lchar,rchar;
  119. a[] = col[] = ;
  120. while(~sf("%c %c%d,%d%c\n",&op,&lchar,&r,&t,&rchar))
  121. {
  122. r<<=;
  123. t<<=;
  124. if(lchar == '(') r++;
  125. if(rchar == ')') t--;
  126. update(op,r,t,,MAXN,);
  127. }
  128. query(,MAXN,);
  129. int s = -,e;
  130. bool flag = false;
  131. for(int i=;i<=MAXN;i++)
  132. {
  133. if(vis[i])
  134. {
  135. if(s == -) s = i;
  136. e = i;
  137. }
  138. else
  139. {
  140. if(s!=-)
  141. {
  142. if(flag) pf(" ");
  143. pf("%c%d,%d%c",s&?'(':'[',s>>,(e+)>>,e&?')':']');
  144. s = -;
  145. flag = true;
  146. }
  147. }
  148. }
  149. if(!flag) printf("empty set");
  150. return ;
  151.  
  152. }

POJ 3225 线段树区间更新(两种更新方式)的更多相关文章

  1. POJ 3225 (线段树 区间更新) Help with Intervals

    这道题搞了好久,其实坑点挺多.. 网上找了许多题解,发现思路其实都差不多,所以就不在重复了. 推荐一篇比较好的题解,请戳这. 另外,如果因为可能要更新多次,但最终查询只需要一次,所以没有写pushup ...

  2. HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧)

    HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧) 题意分析 题目大意:一个h*w的公告牌,要在其上贴公告. 输入的是1*wi的w值,这些是公告的尺寸. 贴公告 ...

  3. POJ 3667 线段树区间合并

    http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html 用线段树,首先要定义好线段树的节点信息,一般看到一个问题,很难很 ...

  4. poj 2528 线段树区间修改+离散化

    Mayor's posters POJ 2528 传送门 线段树区间修改加离散化 #include <cstdio> #include <iostream> #include ...

  5. Mayor's posters POJ - 2528 线段树区间覆盖

    //线段树区间覆盖 #include<cstdio> #include<cstring> #include<iostream> #include<algori ...

  6. poj 3468 线段树区间更新/查询

    Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...

  7. hdu 1698+poj 3468 (线段树 区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 这个题意翻译起来有点猥琐啊,还是和谐一点吧 和涂颜色差不多,区间初始都为1,然后操作都是将x到y改为z,注 ...

  8. poj 2777 线段树 区间更新+位运算

    题意:有一个长板子,分成多段,有两种操作,第一种是C给从a到b那段染一种颜色c,另一种是P询问a到b有多少种不同的颜色.Sample Input2 2 4  板长 颜色数目 询问数目C 1 1 2P ...

  9. POJ 3667 线段树区间合并裸题

    题意:给一个n和m,表示n个房间,m次操作,操作类型有2种,一种把求连续未租出的房间数有d个的最小的最左边的房间号,另一个操作时把从x到x+d-1的房间号收回. 建立线段树,值为1表示未租出,0为租出 ...

随机推荐

  1. SDUT OJ 数据结构实验之二叉树七:叶子问题

    数据结构实验之二叉树七:叶子问题 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...

  2. WPF:CheckBox竖向的滑块效果

    原文:WPF:CheckBox竖向的滑块效果 之前做了一个横向的滑块效果,<WPF:CheckBox滑块效果>,其实我觉得那个不好看,今天又做了一个竖向的玩. <Style Targ ...

  3. php 实现无限极分类

    原始数据 $array = array( array('id' => 1, 'pid' => 0, 'n' => '河北省'), array('id' => 2, 'pid' ...

  4. Luogu P1156 垃圾陷阱 DP

    f[i][j]表示在第i个垃圾,高度为j的最大生命值 转移分三部分: 如果j>=当前垃圾的高度,且两个垃圾间的时间小于等于上一个状态f[i-1][j-a[i].v]的生命值,则可以垫高度 如果j ...

  5. HDU - 5050 (大数二进制gcd)

    It's time to fight the local despots and redistribute the land. There is a rectangular piece of land ...

  6. 危险系数(枚举点+bfs)--------蓝桥备战系列

    标题:危险系数 抗日战争时期,冀中平原的地道战曾发挥重要作用. 地道的多个站点间有通道连接,形成了庞大的网络.但也有隐患,当敌人发现了某个站点后,其它站点间可能因此会失去联系.        我们来定 ...

  7. POJ - 3233 矩阵套矩阵

    题意:给你矩阵\(A\),求\(S=\sum_{i=1}^{k}A^i\) 构造矩阵 \[ \begin{bmatrix} A & E \\ 0 & E\\ \end{bmatrix} ...

  8. 有用的 Angular CLI 命令参数

    这是一些有用的 Angular 5 CLI 命令参数,注意参数前面的-和--的不同... 1. 指定build的输出为production version,合并优化css and js files. ...

  9. 在python3.5中pip安装scrapy,遇到 error: Microsoft Visual C++ 14.0 is required

    本来在python3.5中安装scrapy一路顺畅(pip install scrapy),中间遇到一个 error: Microsoft Visual C++ 14.0 is required. x ...

  10. PIE SDK地图范围设置

    1.功能简介 地图范围设置主要就是对图层的地图浏览控制,例如地图的放大.缩小.漫游.全图显示.1:1视图.比例尺等功能,能更好的与地图有一个互动的地图浏览体验.PIE SDK对地图范围设置主要利用IC ...