题意:贴海报
有一面很长的墙,大概有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;
}

最新文章

  1. .NET 程序集单元测试工具 SmokeTest 应用指南
  2. RMAN还原遭遇ORA-32006&amp;ORA-27102错误
  3. Kali Linux (XFce版本)安装后的一些设置
  4. 简单的 http 服务器
  5. mysql select语句解析
  6. 边工作边刷题:70天一遍leetcode: day 85
  7. 某代理网站免费IP地址抓取测试
  8. ARM的QT phonon 的移植
  9. windowSoftInputMode属性详解
  10. PostgreSQL中如何查询在当前的哪个数据库中
  11. (转)Ubuntu中使用dpkg安装deb文件提示依赖关系问题,仍未被配置
  12. 为什么要学习Java EE
  13. 201521123009 《Java程序设计》第12周学习总结
  14. php根据ip段以及子网掩码,判断某ip是否处于某子网下
  15. 为什么说android UI操作不是线程安全的
  16. JPype1使用总结
  17. [转载] 相机越贵画质越好?聊聊CMOS设计
  18. ftp 自动上传数据库备份文件
  19. BOM知识梳理
  20. win10无法使用内置管理员账户打开应用

热门文章

  1. 刚入门的easyui
  2. OD: Kernel Exploit - 1
  3. &lt;c:if&gt;判断参数是否同时为空
  4. MemCache缓存和C#自带的Cache缓存
  5. LINQ to SQL 基础
  6. 对ajax的hack的分析
  7. 用css样式,为表格加入边框
  8. SQL window身份登陆 SQL server不能登陆
  9. Animator Override Controllers 学习及性能测试
  10. 二十分钟弄懂C++11 的 rvalue reference (C++ 性能剖析 (5))