见代码。

  1. /*
  2. 线段树+Lazy
  3. 题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度。
  4. 现在往墙上贴N张海报,每张海报的宽度是任意的,但是必定是单位宽度的整数倍,且<=1QW。
  5. 后贴的海报若与先贴的海报有交集,后贴的海报必定会全部或局部覆盖先贴的海报。
  6. 现在给出每张海报所贴的位置(左端位置和右端位置),问张贴完N张海报后,还能看见多少张海报?
  7. (PS:看见一部分也算看到。)
  8. */
  9. #include<stdio.h>
  10. #include<string.h>
  11. #include<stdlib.h>
  12. #include<algorithm>
  13. #include<iostream>
  14. #include<queue>
  15. #include<map>
  16. #include<stack>
  17. #include<set>
  18. #include<math.h>
  19. using namespace std;
  20. typedef long long int64;
  21. //typedef __int64 int64;
  22. typedef pair<int64,int64> PII;
  23. #define L(x) (x<<1)
  24. #define R(x) (x<<1|1)
  25. #define MP(a,b) make_pair((a),(b))
  26. const int maxn = ;
  27. const int inf = 0x7fffffff;
  28. const double pi=acos(-1.0);
  29. const double eps = 1e-;
  30.  
  31. struct Node{
  32. int L,R,color;
  33. }tree[ maxn<< ];
  34. struct NODE{
  35. int L,R;
  36. bool operator<(const NODE &tmp ) const{
  37. return R<tmp.R;
  38. }
  39. }a[ maxn ];
  40. int myhash[ maxn ];
  41. int ANS;
  42. int vis[ maxn ];
  43.  
  44. int lisanhua( int k ){
  45. sort( myhash,myhash+k );
  46. int cnt = unique( myhash,myhash+k ) - myhash;
  47. return cnt;
  48. }
  49.  
  50. void build( int L,int R,int n ){
  51. if( L==R ){
  52. tree[ n ].L = L;
  53. tree[ n ].R = R;
  54. tree[ n ].color = ;
  55. return ;
  56. }
  57. tree[ n ].L = L;
  58. tree[ n ].R = R;
  59. tree[ n ].color = ;
  60. int mid = (L+R)/;
  61. build( L,mid,L(n) );
  62. build( mid+,R,R(n) );
  63. }
  64.  
  65. void PushDown( int n,int new_color ){
  66. if( tree[ n ].color!=&&tree[ n ].color!=new_color ){
  67. tree[ L(n) ].color = tree[ R(n) ].color = tree[ n ].color;
  68. tree[ n ].color = ;
  69. }
  70. }
  71.  
  72. void update( int x,int y,int new_color,int L,int R,int n ){
  73. if( x==L&&y==R ){
  74. tree[ n ].color = new_color;
  75. return ;
  76. }
  77. PushDown( n,new_color );
  78. int mid = (L+R)/;
  79. if( mid>=y ) update( x,y,new_color,L,mid,L(n) );
  80. else if( mid<x ) update( x,y,new_color,mid+,R,R(n) );
  81. else {
  82. update( x,mid,new_color,L,mid,L(n) );
  83. update( mid+,y,new_color,mid+,R,R(n) );
  84. }
  85. }
  86.  
  87. void query( int n ){
  88. if( tree[n].color ){
  89. if( vis[tree[n].color]== ){
  90. vis[tree[n].color] = ;
  91. ANS++;
  92. }
  93. return ;
  94. }
  95. //int mid = (tree[n].L+tree[n].R)/2;
  96. query( L(n) );
  97. query( R(n) );
  98. }
  99.  
  100. int main(){
  101. int T;
  102. scanf("%d",&T);
  103. while( T-- ){
  104. int n;
  105. scanf("%d",&n);
  106. int k = ;
  107. for( int i=;i<=n;i++ ){
  108. scanf("%d%d",&a[i].L,&a[i].R);
  109. myhash[ k++ ] = a[i].L;
  110. myhash[ k++ ] = a[i].R;
  111. }
  112. int cnt = lisanhua( k );
  113. build( ,cnt, );
  114. //printf("build\n");
  115. for( int i=;i<=n;i++ ){
  116. int x = lower_bound( myhash,myhash+cnt,a[i].L )-myhash;
  117. int y = lower_bound( myhash,myhash+cnt,a[i].R )-myhash;
  118. x++,y++;
  119. //printf("i = %d\n",i);
  120. //printf("x = %d, y=%d\n",x,y);
  121. update( x,y,i,,cnt, );
  122. }
  123. ANS = ;
  124. memset( vis,,sizeof( vis ) );
  125. //printf("query\n");
  126. query( );
  127. printf("%d\n",ANS);
  128. }
  129. return ;
  130. }

POJ2528+线段树的更多相关文章

  1. poj-2528线段树练习

    title: poj-2528线段树练习 date: 2018-10-13 13:45:09 tags: acm 刷题 categories: ACM-线段树 概述 这道题坑了我好久啊啊啊啊,,,, ...

  2. poj2528(线段树+离散化)Mayor's posters

    2016-08-15 题意:一面墙,往上面贴海报,后面贴的可以覆盖前面贴的.问最后能看见几种海报. 思路:可以理解成往墙上涂颜色,最后能看见几种颜色(下面就是以涂色来讲的).这面墙长度为1~1000 ...

  3. POJ2528 线段树的区间操作

    首先应该对该[0,10000000]进行离散化 即先将点集进行排序,然后从小到大缩小其中的间距,使得最后点数不会超过2*n 然后就是线段树操作 只需进行染色,然后最后用nlgn进行一个个查询颜色记录即 ...

  4. poj2528 线段树+离散化 (倒序)

    The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...

  5. poj2528线段树解题报告,离散化+线段树

    题目网址:http://poj.org/problem?id=2528 题意: n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=1 ...

  6. poj2528(线段树区间替换&离散化)

    题目链接: http://poj.org/problem?id=2528 题意: 第一行输入一个 t 表 t 组输入, 对于每组输入: 第一行  n 表接下来有 n 行形如 l, r 的输入, 表在区 ...

  7. POJ2528线段树基础

    開始就直接用延迟标记搞了下.最后发现内存肯定会爆了.数据太大了. 问了瓜神,原来应该用离散化来做这题,详细见凝视 #include <cstdio> #include <cstrin ...

  8. POJ2528线段树段更新逆序异或(广告牌)

    题意:      可以这样理解,有一条直线,然后用n条线段去覆盖,最后问全部都覆盖完之后还有多少是没有被完全覆盖的. 思路:      一开始想的有点偏,想到起点排序,然后..失败了,原因是忘记了题目 ...

  9. poj2528 线段树+离散化

    由于坐标可能很大,此时需要离散化,将值转化为对应的坐标. #include<stdio.h> #include<algorithm> using namespace std; ...

随机推荐

  1. asp.net select Case条件语句的使用方法

    原文:http://www.111cn.net/net/vb-net/38548.htm 如果 testexpression 与任何 Case expressionlist 表达式匹配 ,则执行此 C ...

  2. sql语句聚合等疑难问题收集

    ------------------------------------------------------------------------------------ 除法运算 select 500 ...

  3. 使用C#通过调用minitab的COM库自动化生成报表

    本文介绍通过C#调用minitab com组建自动化生成报表的方法. 首先需要在minitab中通过手动配置的方式生成报表来得到该报表的命令行,过程如下 选择菜单“编辑器”->“启用命令”启用命 ...

  4. 基于AspectJ自定义注解

    package com.aspectj.demo.aspect; import java.lang.annotation.ElementType; import java.lang.annotatio ...

  5. java实现的一个maven多模块项目自动生成工具

    平时在做spring mvc web新项目时,都需要自己去搭建spring mvc的项目框架,包括基本pom 依赖引入,基本配置文件(web.xml,spring-mvc.xml,数据库配置文件等等) ...

  6. new失败判断

    使用 malloc/calloc 等分配内存的函数时,一定要检查其返回值是否为空;但是C++ 里,如果 new 分配内存失败,默认是抛出bad_alloc异常,不会返回空:但是有些编译器对c++标准支 ...

  7. 基数排序(RadixSort)

    1 基数排序的特点是研究多个关键字key,且多个key之间有权重之分,    或者可把单个key建模为含有多个key的排序 而计数排序.桶排序始终只有个一个key,或者说围绕着一个比较规则 Ex:比较 ...

  8. poj 2154 Color

    这是道标准的数论优化的polya题.卡时卡的很紧,需要用int才能过.程序中一定要注意控制不爆int!!!我因为爆intWA了好久=_=…… 题目简洁明了,就是求 sigma n^gcd(i,n):但 ...

  9. xamarin android——数据绑定到控件(四)

    本文为通过自定义列表适配器定义ListView,以上文为基础,基于ListActivity. 定义列表项布局,包含一个图片显示,标题和描述 <LinearLayout xmlns:android ...

  10. linux环境下配置github远程仓库

    1.设置git用户和邮箱 git config --global user.name "fujinzhou" git config --global user.email &quo ...