• 题意:一个坐标轴从1~1e7,每次覆盖一个区间(li,ri),问最后可见区间有多少个(没有被其他区间挡住的)
  • 线段树,按倒序考虑,贴上的地方记为1,每次看(li,ri)这个区间是否全是1,全是1就说明在它后面贴的把它给挡住了,否则该海报可见。
  • 然后就愉快的MLE了。。。。
  • 再看看数据范围,离散化如下,比如如果海报的左右端点如下
  • 那图中橙色的一块的大小其实对结果没有影响,可以把他们都缩为1

  • 最后离散化结果如下图:

  • 代码:

     #include <algorithm>
    #include <iostream>
    #include <cstdio>
    #define nmax 10010
    #define tn t[node]
    #define sl (node<<1)
    #define sr (1+(node<<1)) using namespace std;
    int n;
    int inl[nmax],inr[nmax];
    struct tin{
    int pd,id,num,n2; //0 ->l 1->r
    bool operator < (const tin x) const { return x.num>num; }
    }in[nmax*];
    struct segt { int l,r,v; }t[nmax*]; void build(int node,int l,int r){
    tn.l=l;
    tn.r=r;
    tn.v=;
    if(l==r) return;
    int mid=(l+r)>>;
    build(sl,l,mid);
    build(sr,mid+,r);
    } int upd(int l,int r,int node,int tv){
    int ta=(tv||tn.v);
    if(tn.l>=l&&tn.r<=r) tn.v=;
    else{
    int mid=(tn.l+tn.r)>>;
    int tl=,tr=;
    if(l<=mid) tl=upd(l,r,sl,tv||tn.v);
    if(r>mid) tr=upd(l,r,sr,tv||tn.v);
    ta=(tl&&tr)||tv;
    tn.v=tn.v||(t[sl].v&&t[sr].v);
    }
    return ta;
    } int main(){
    int cas;
    cin>>cas;
    while(cas--){
    cin>>n;
    for (int i=; i<n; i++) {
    scanf("%d%d",&in[i].num,&in[i+n].num);
    in[i].pd=;
    in[i+n].pd=;
    in[i].id=in[i+n].id=i;
    }
    sort(in,in+*n);
    //离散化
    int w=;
    in[].n2=(++w);
    for (int i=; i<*n; i++) {
    if(in[i].num==in[i-].num ) {
    in[i].n2=w;
    continue;
    }
    in[i].n2=(++w);
    if( in[i].num!=in[i-].num+ ) in[i].n2=(++w);
    }
    //离散化over
    build(,,w);
    for (int i=; i<*n; i++) if(in[i].pd) inr[in[i].id]=in[i].n2; else inl[in[i].id]=in[i].n2;
    int ans=;
    for (int i=n-; i>=; i--) if(upd(inl[i],inr[i],,)==) ans++;
    printf("%d\n",ans);
    }
    return ;
    }

POJ2528Mayor's posters 线段树,离散化技巧的更多相关文章

  1. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

  2. POJ2528Mayor's posters[线段树 离散化]

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59683   Accepted: 17296 ...

  3. POJ 2528 Mayor's posters(线段树+离散化)

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  4. [poj2528] Mayor's posters (线段树+离散化)

    线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...

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

    Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...

  6. Mayor's posters(线段树+离散化POJ2528)

    Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51175 Accepted: 14820 Des ...

  7. POJ 2528 Mayor's posters (线段树+离散化)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:75394   Accepted: 21747 ...

  8. poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化

    Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...

  9. poj 2528 Mayor's posters(线段树+离散化)

    /* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...

随机推荐

  1. 基于BTrace监控调试Java代码

    BTrace是Java的一个动态代码追踪工具,通过编写btrace脚本,它可以动态的向目标应用程序的字节码注入追踪代码,通过修改字节码的方式,达到监控调试和定位问题的目的,是解决线上问题的利器. BT ...

  2. 11种常用css样式之开篇文本字体学习

    常见css样式:1.字体与颜色2.背景属性3.文本属性4.边框属性5.鼠标光标属性6.列表样式7.定位属性8.内外边距9.浮动和清除浮动10.滚动条11.显示和隐藏 文本:1.letter-spaci ...

  3. Android 有关在ListView RecycleView 中使用EditText Checkbox的坑

    这是一篇文字超多的博客,哈哈哈,废话自行过滤··· 遇到问题 在开发中我们常会在ListView , RecycleView 列表中添加EditText输入框,或者checkbox复选框.   复选框 ...

  4. 有关版本控制--SVN

    什么是版本控制? 这个之前有记录过相关的内容 版本管理就是管理更新的历史记录, 它给我们提供了一些在软件开发过程中必不可少的功能,例如: 记录一款软件添加或更改源代码的过程 回滚到特定阶段,恢复误删除 ...

  5. Git安装配置及第一次上传项目到GitHub

    平时的学习工作少不了保存自己的Code到代码库,这里必须要使用到Git与GitHub. 1.   关于Git的安装 下载Git:下载地址:https://git-scm.com/downloads  ...

  6. 洛谷 P4298: bzoj 1143: [CTSC2008]祭祀

    题目传送门:洛谷 P4298. 题意简述: 给定一个 \(n\) 个点,\(m\) 条边的简单有向无环图(DAG),求出它的最长反链,并构造方案. 最长反链:一张有向无环图的最长反链为一个集合 \(S ...

  7. fastJson&edis

    fastJson&redis 1. fastJson 1.1 依赖 <dependency> <groupId>com.alibaba</groupId> ...

  8. JSP其余内置对象及四大范围对象的使用

    一.application String getContextPath():获取虚拟路径String getRealPath():获取虚拟路径对应的绝对路径 实例 application.jsp &l ...

  9. CMD命令下图片合成一句话木马命令

    非常简单,我们只需要一张图片1.jpg一句话木马写好的php文件 1.php之后我们进入到命令行.注意:将php文件和图片文件放到同一目录下,cmd也要跳转到放文件的目录下之后执行命令 copy .j ...

  10. SpringCloud踩坑

    今天在使用 SpringCloud 时遇到了一个问题,感觉有不少小伙伴会遇到,所以记录下来 版本说明 SpringBoot 2.2.4.RELEASE SpringCloud Greenwich.SR ...