题意:贴海报
有一面很长的墙,大概有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. 织梦DedeCMS广告管理模块增加图片上传功能插件

    网站广告后台管理非常方便,但是织梦后台的广告管理模块,发布广告时图片没有上传选项,只能用URL地址,很不方便,那么下面就教大家一个方法实现广告图片后台直接上传,非常方便. 先给大家看下修改后的广告图片 ...

  2. css3中-webkit-text-size-adjust详解

    1.当样式表里font-size<12px时,中文版chrome浏览器里字体显示仍为12px,这时可以用 html{-webkit-text-size-adjust:none;} 2.-webk ...

  3. Linux基本权限

    首先需要我们了解的是,权限(rwx)对于文件和目录的作用是不一样的 . 权限对文件的作用 r : 读取文件内容(cat , more , head , tail) w: 编辑.新增.修改文件内容(vi ...

  4. 该项目中不存在目标 precomputecompiletypescript The target "PreComputeCompileTypeScript" does not exist in the project

    Open Microsoft.TypeScript.targets file located under C:\Program Files (x86)\MSBuild\Microsoft\Visual ...

  5. iOS扫描二维码(系统方法)

    步骤如下: 1.导入AVFoundation框架,引入<AVFoundation/AVFoundation.h> 2.设置一个用于显示扫描的view 3.实例化AVCaptureSessi ...

  6. [转]Delphi 中 image 控件加载bmp、JPG、GIF、PNG等图片的办法

    procedure TForm1.Button1Click(Sender: TObject); var jpg: TJPEGImage; // 要use Jpeg单元 begin // 显示jpg大图 ...

  7. PHP PDO 简单登陆操作

    用PHP做出一个简单的登陆操作,确实很简单,下面就让我给大家简单的介绍一下PDO做出一个登陆界面操作的过程,因为也是初学乍练,不足之处请大家包涵. 首先,首先还要建一个表,在MySQL中建表,核心代码 ...

  8. wariging for you oh~

  9. php小知识点

    1.字符串可以里面的字符可以像数组一样访问,比如$s = "123";$s[1]就等于2,如果字符串为中文则会乱码,需要使用mb_substr进行截取: 2.php中的单引号(' ...

  10. iPhone 6 图像渲染揭秘(转)

    几天前,Apple发布了iPhone 6 Plus. 新的iPhone大幅改变了图像在屏幕上渲染的方式.我们做了一个图表进行详细分析. 分析. 转自:转送