• 题意:一个坐标轴从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. #《H.264和MPEG-4视频压缩》# 一. 色彩空间

    多数的数字视频应用需要播放彩色的视频信号,所以需要捕获和重现颜色信息.一幅黑白图像的每一个采样点只需要一个像素表示明暗或亮度,而在彩色图像中至少需要3个像素来表示每个像素的色彩.表示亮度和色彩的不同方 ...

  2. Ubuntu安装软件时报 Unable to acquire the dpkg frontend lock解决方案

    解决方案如下: 对于以上内容,请等待过程完成.如果这没有发生,请在终端中运行: sudo killall apt apt-get 如果以上都不起作用,请删除锁定文件.在终端中运行: sudo rm / ...

  3. 关键字Lock的简单小例子

    一.什么是Lock? Lock——字面上理解就是锁上:锁住:把……锁起来的意思: 为什么要锁?要锁干什么?——回到现实中可想象到,这个卫生间我要上,其他人不要进来!(所以我要锁住门):又或者土味情话所 ...

  4. 并发编程之J.U.C的第一篇

    并发编程之J.U.C AQS 原理 ReentrantLock 原理 1. 非公平锁实现原理 2)可重入原理 3. 可打断原理 5) 条件变量实现原理 3. 读写锁 3.1 ReentrantRead ...

  5. EasyUI笔记(三)Window窗口

    本系列只列出一些常用的属性.事件或方法,具体完整知识请查看API文档 Window(窗口) 窗口控件是一个浮动和可拖拽的面板可以用作应用程序窗口.默认情况下,窗口可以移动,调整大小和关闭.它的内容也可 ...

  6. P2813 母舰

    ------------------------------------------- 链接:P2813 ------------------------------------------- 一道贪 ...

  7. Android日期时间控件DatePickerDialog和TimePickerDialog

    1.DatePickerDialog 在一些万年历.日程表等APP上我们经常可以看到日期选择控件,由于很少有用户会老老实实的手工输入日期,所以该控件的作用就是为了控制用户的输入格式,在Android中 ...

  8. java递归方法分析

    测试题目: 使用递归方式判断某个字串是否是回文( palindrome )“回文”是指正着读.反着读都一样的句子.比如“我是谁是我” 设计思路: 第一,判断是不是回文序列的条件是每一对对称位置的字符是 ...

  9. Ansible-Tower使用文档

    导航栏介绍 # viewes Dashboard 仪表盘展示信息的 Jobs 跑过的任务记录 Schedules 计划任务 My View 查看用户的工作模版,和任务记录 # resources Te ...

  10. 双向链表的简单Java实现-sunziren

    写在前面,csdn的那篇同名博客就是我写的,我把它现在在这边重新发布,因为我实在不想用csdn了,那边的广告太多了,还有就是那个恶心人的“阅读更多”按钮,惹不起我躲得起. 在上次分享完单向链表的简单编 ...