• 题意:一个坐标轴从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. 不懂怎么创建可视化大屏?手把手教你使用数据可视化BI软件创建工厂车间数据监控大屏

    灯果数据可视化BI软件是新一代人工智能数据可视化大屏软件,内置丰富的大屏模板,可视化编辑操作,无需任何经验就可以创建属于你自己的大屏.大家可以在他们的官网下载软件.   本文以工厂车间数据监控大屏为例 ...

  2. App工程结构

    在经过千辛万苦各种填坑终于安装好了Android Studio之后,在其自带的模拟器上成功运行了第一个APP(hello world),通过这个APP首先研究了一下APP基本的工程结构,从而使后面的开 ...

  3. 【转】Makefile步步为营

    Makefile步步为营 本目录主要包含Makefile一步步递进学习的示例代码 makefile代码实例:https://www.lanzous.com/i9m9npi step0:Makefile ...

  4. 剑指offer-面试题65-不用加减乘除做加法-位运算

    /* 题目: 在不使用加减乘除的前提下,计算两个整数之和. 思路: 不能使用加减乘除则只能考虑位运算. x=num1^num2,则为抹掉进位的结果. y=num1&num2,为只有进位的结果. ...

  5. python实现串口通讯小程序(GUI界面)

    python实现串口通讯小程序(GUI界面) 使用python实现串口通讯需要使用python的pyserial库来实现,这个库在安装python的时候没有自动进行安装,需要自己进行安装. 1.安装p ...

  6. nCompass-产品配置基础

    nCompass-产品配置基础 设备上架后,浏览器登陆设备的管理IP,输入用户名和密码, 登入进入视图展示页面 1. 添加许可 新设备上架之后,要添加许可方能使用. 步骤: 系统设置 --- 许可-- ...

  7. JS淘宝小广告

    <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8 ...

  8. Java垃圾回收手册翻译 - 什么是垃圾回收

    Java垃圾回收手册翻译 - 什么是垃圾回收 初看之下,垃圾回收应该要做其名称之事 - 找到和丢掉垃圾.然而事实上它正好做着相反的事,垃圾回收会记录所有仍在使用中的对象,然后将其他标记为垃圾.谨记这点 ...

  9. CF1310D Tourism

    吐槽: 为什么这场CF-不寻常,1D不应该是2F么-[悲] 题意: 给定一个完全图,路径带权且 \(dis_{i,j}\) 不一定等于 \(dis_{j,i}\),边数为\(k\)不存在奇环且起点和终 ...

  10. bzoj3162独钓寒江雪

    题意 \(n\)阶树,求本质不同的独立集个数 做法 重新编号后重心是不变的,如果有两个重心,可以加个虚点 用树哈希判子树有多少个相同的子树,设某种有\(k\)个,如果原本方案数为\(x\)个 则方案数 ...