题意:贴海报
有一面很长的墙,大概有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. apk代码的破解

    方法一:dexdump方法(效果很不好,推荐指数*) 1.搜索到dexdump.exe所在目录: 2.将apk包中的**.dex文件存放到上面目录: 3.命令行中进入上面目录,执行:dexdump   ...

  2. python函数的使用和返回值

    #coding=utf-8 def a(): i=1a() #函数的返回值,用return语句实现 #一个返回值的情况def test(): i=7 return iprint test() #多个返 ...

  3. HTML5 Canvas Text文本居中实例

    1.代码: <canvas width="700" height="300" id="canvasOne" class="c ...

  4. CSS中表示cellpadding和cellspacing的方法

    本文和大家重点讨论一下用CSS来表示表格的cellpadding和cellspacing方法,表格的cellpadding和cellspacing我们经常会用一定的方式来清除默认样式,请看下文详细介绍 ...

  5. leetcode修炼之路——83. Remove Duplicates from Sorted List

    哈哈,我又来了.昨天发现题目太简单就没有放上来,今天来了一道有序链表的题.题目如下: Given a sorted linked list, delete all duplicates such th ...

  6. PLSQL远程连接到Oracle服务器

    这里只介绍一种远程连接服务器方法,即本机安装了Oracle客户端和PLSql工具,服务器安装在虚拟机或者另一台电脑上 1.打开Oracle客户端的Net Manager,选择Oracle Net配置— ...

  7. Hive学习之四 《Hive分区表场景案例应用案例,企业日志加载》 详解

    文件的加载,只需要三步就够了,废话不多说,来直接的吧. 一.建表 话不多说,直接开始. 建表,对于日志文件来说,最后有分区,在此案例中,对年月日和小时进行了分区. 建表tracktest_log,分隔 ...

  8. 你好,C++(11)如何用string数据类型表示一串文字?根据初始值自动推断数据类型的auto关键字(C++ 11)

    3.5.2  字符串类型 使用char类型的变量我们可以表示单个字符,那么,我们又该如何表示拥有多个字符的字符串呢? 我们注意到,一个字符串是由多个字符串连起来形成的.很自然地,一种最简单直接的方法就 ...

  9. 【COGS495】窗口

    [问题描述] 给你一个长度为N的数组,一个长为K的滑动的窗体从最左移至最右端,你只能见到窗口的K个数,每次窗体向右移动一位,如下表: Window position Min value Max val ...

  10. javascript定义变量和优先级的问题

    本文链接: javascript定义变量和优先级的问题.转载请保留.   看下面的代码: if (!("aa" in window)) { alert('oh my god'); ...