题意:贴海报
有一面很长的墙,大概有10000000 这么长,现有有一些海报会贴在墙上,当然贴海报的顺序是有先后的,问你当最后一张海报也贴上的时候能不能求出来在这面墙上能看到多少张不同的海报?
分析:因为后面贴的海报会把前面贴的覆盖掉,不太容易求出来,但是如果从最后一张倒着贴,只要判断墙上这段区间有没有被完全覆盖就可以了,因为墙比较长,所以需要离散化一下。
************************************************************************
注意:在向上跟新的时候返回值要在更新的下面要不直接返回了怎么更新??
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std; const int maxn = 40005; int Hash[maxn];//记录离散化后的数据
struct Post{int l, r;}p[maxn];//记录海报
struct Tree
{
    int L, R;
    bool isCover;//记录这段区间是否被覆盖
    int Mid(){return (L+R)/2;}
}tree[maxn*4]; void Up(int root)//向上更新,如果左右子树都被覆盖,那么他也会被覆盖
{
    if(tree[root].L != tree[root].R)
    if(tree[root<<1].isCover && tree[root<<1|1].isCover)
        tree[root].isCover = true;
}
void Build(int root, int L, int R)
{
    tree[root].L = L, tree[root].R = R;
    tree[root].isCover = false;     if(L == R)return ;     Build(root<<1, L, tree[root].Mid());
    Build(root<<1|1, tree[root].Mid()+1, R);
}
//如果区间能内还有位置返回真,否则返回假
bool Insert(int root, int L, int R)
{
    if(tree[root].isCover)return false;     if(tree[root].L == L && tree[root].R == R)
    {
        tree[root].isCover = true;
        return true;
    }
    
    bool ans;     if(R <= tree[root].Mid())
        ans =  Insert(root<<1, L, R);
    else if(L > tree[root].Mid())
        ans =  Insert(root<<1|1, L, R);
    else
    {
        bool Lson = Insert(root<<1, L, tree[root].Mid());
        bool Rson = Insert(root<<1|1, tree[root].Mid()+1, R);         ans = Lson | Rson;
    }     Up(root);     return ans;
} int main()
{
    int T;     scanf("%d", &T);     while(T--)
    {
        int i, N, nh=0;         scanf("%d", &N);         for(i=1; i<=N; i++)
        {
            scanf("%d%d", &p[i].l, &p[i].r);
            Hash[nh++] = p[i].l, Hash[nh++] = p[i].l-1;
            Hash[nh++] = p[i].r, Hash[nh++] = p[i].r+1;
        }
        sort(Hash, Hash+nh);
        nh = unique(Hash, Hash+nh) - Hash;         Build(1, 1, nh);         int ans = 0;         for(i=N; i>0; i--)
        {
            int l = lower_bound(Hash, Hash+nh, p[i].l) - Hash;
            int r = lower_bound(Hash, Hash+nh, p[i].r) - Hash;             if(Insert(1, l, r) == true)
                ans += 1;
        }         printf("%d\n", ans);
    }     return 0;
}

D - Mayor's posters - 2528(区间覆盖)的更多相关文章

  1. POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】

    任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  2. POJ 2528 - Mayor's posters - [离散化+区间修改线段树]

    题目链接:http://poj.org/problem?id=2528 Time Limit: 1000MS Memory Limit: 65536K Description The citizens ...

  3. POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)

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

  4. POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)

    题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...

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

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

  6. POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)

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

  7. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  8. POJ 2528 Mayor's posters(线段树/区间更新 离散化)

    题目链接: 传送门 Mayor's posters Time Limit: 1000MS     Memory Limit: 65536K Description The citizens of By ...

  9. poj 2528 Mayor's posters 线段树区间更新

    Mayor's posters Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...

随机推荐

  1. ubuntu 配置android开发环境

    本文的下载地址都是androiddevtools,下载地址:http://www.androiddevtools.cn/ 一.安装android sdk 解压文件,全部放到/opt/Java/andr ...

  2. Proxy 代理模式

    简介 代理模式是用一个简单的对象来代替一个复杂的或者创建耗时的对象. java.lang.reflect.Proxy RMI 代理模式是对象的结构模式.代理模式给某一个对象提供一个代理对象,并由代理对 ...

  3. 码表 ASCII Unicode GBK UTF-8

    2017-1-3 [ASCII]一个字节(7位,128个字符,2个16进制) 不包含中文 ASCII(American Standard Code for Information Interchang ...

  4. datagrid加下拉列表dropdownlist

    datagrid中代码: <asp:datagrid id="dgList" runat="server" ItemStyle-HorizontalAli ...

  5. Asp.net Core 部署到Azure.cn的一个小问题

    前一段尝试在azure.cn上部署Aps.net Core未成功,报503错误!在网上查到是Azure.cn的问题,未能完美支持Asp.net Core! Asp.net Core发表正式版了,又尝试 ...

  6. asp.net中Request.ServerVariables的用法

    在asp.net中可以通过HttpRequest.ServerVariables 属性来获取“ Web 服务器变量的集合” HttpRequest.ServerVariables 的用法: HttpR ...

  7. 牛顿法与拟牛顿法,DFP法,BFGS法,L-BFGS法

    牛顿法 考虑如下无约束极小化问题: $$\min_{x} f(x)$$ 其中$x\in R^N$,并且假设$f(x)$为凸函数,二阶可微.当前点记为$x_k$,最优点记为$x^*$. 梯度下降法用的是 ...

  8. Ubuntu下管理员界面的切换

    不同于redhat的Linux系统可以通过命令su root 简单地切换到管理员状态,ubuntn 默认是没有超级用户的,因此如需使用管理员权限可以使用以下2种方法: 1.sudo -i 此命令不需要 ...

  9. 加入BOINC(伯克利开放式网络计算平台)

    转载:BOINC:为科学而计算 通过 BOINC 你可以将闲置的计算机时间贡献给 SETI@home, Climateprediction.net, Rosetta@home, World Commu ...

  10. 面向对象设计模式之Flyweight享元模式(结构型)

    动机:采用纯粹对象方案的问题在于大量细粒度的对象会很快充斥在系统中,从而带来很高的运行代价——主要指内存需求方面的代价.如何在避免大量细粒度对象问题的同 时,让外部客户程序仍然能够透明地使用面向对象的 ...