有一块很长的画布,现在想在这块画布上画一些颜色,不过后面画的颜色会把前面画的颜色覆盖掉,现在想知道画完后这块画布的颜色分布,比如 1号颜色有几块,2号颜色有几块。。。。
***********************************************************************
分析:基本上跟帖海报是一样的,不过最后要求输出的是这种颜色的画有几块,可以按照贴海报的方式先做出来,然后对每个点进行查询,不晓得复杂度会不会太高。不过还是先试一下吧。
注意:如果出现 
Segmentation Fault
可以看看是不是树建的小了,不能拿N建树
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define Lson root<<1,L,tree[root].Mid()
#define Rson root<<1|1,tree[root].Mid()+1,R const int maxn = ; struct Hook{int l, r, c;}p[maxn];
struct Tree{
    int L, R;
    int color;//记录颜色
    int Mid(){return (L+R)/;}
}tree[maxn*];
int Color[maxn]; void CoverColor(int L, int R, int e)//把区间LR涂成颜色e
{
    for(int i=L; i<=R; i++)
        Color[i] = e;
} void Build(int root, int L, int R)
{
    tree[root].L = L, tree[root].R = R;
    //0代表没有被颜色覆盖,1代表未覆盖,2代表子树有被别的颜色覆盖
    tree[root].color = ;     if(L == R)return ;     Build(Lson);
    Build(Rson);
}
void Up(int root)
{
    if(tree[root].L != tree[root].R)
    if(tree[root<<].color ==  && tree[root<<|].color == )
        tree[root].color = ;
}
void Insert(int root, int L, int R, int e)
{
    if(tree[root].color == )return ;     if(tree[root].L == L && tree[root].R == R && !tree[root].color)
    {
        tree[root].color = ;
        CoverColor(L, R, e);
        return ;
    }
    tree[root].color = ;     if(R <= tree[root].Mid())
        Insert(root<<, L, R, e);
    else if(L > tree[root].Mid())
        Insert(root<<|, L, R, e);
    else
    {
        Insert(Lson, e);
        Insert(Rson, e);
    }     Up(root);
}
int main()
{
    int N;     while(scanf("%d", &N) != EOF)
    {
        int i, ans[maxn] = {};         for(i=; i<=N; i++)
            scanf("%d%d%d", &p[i].l, &p[i].r, &p[i].c);         Build(, , maxn-);
        memset(Color, -, sizeof(Color));         for(i=N; i>; i--)//因为给的是紧密区间,而建的树点的,所以把左边的+1,变成点覆盖的
            Insert(, p[i].l+, p[i].r, p[i].c);         for(i=; i<maxn; i++)
        {
            if( Color[i]!=- && (!i || Color[i]!=Color[i-]) )
                ans[Color[i]]++;
        }         for(i=; i<maxn; i++)if(ans[i])
            printf("%d %d\n", i, ans[i]);
        printf("\n");
    }     return ; } 

最新文章

  1. SetZOrder 无效
  2. win10下JDK的安装与环境变量配置
  3. CSS3初学篇章_7(布局/浏览器默认样式重置)
  4. POJ 2828 Buy Tickets(线段树 树状数组/单点更新)
  5. Codeforces724D [字符串][乱搞][贪心]
  6. 使用multipart请求处理文件上传
  7. 论近年来IT媒体的怪现象
  8. canvas仿屏幕保护运动线条
  9. ManifoldJS
  10. 解决outlook无法启动
  11. mysql Group By
  12. thinkphp5多图上传 js部分
  13. CH4INRULZ从渗透到提权
  14. Java自动内存管理机制学习(一):Java内存区域与内存溢出异常
  15. 用mescroll实现无限上拉增加数据,下拉刷新数据 (学习笔记)
  16. 细说tomcat之集群session共享方案
  17. 怎么从docker 内部去连接host 上的mysql
  18. NLP第3章 中文分词技术
  19. linux几个命令
  20. vue angular 分别实现分页

热门文章

  1. ADO.NET基础
  2. (转)iFrame高度自适应
  3. MemCache缓存和C#自带的Cache缓存
  4. ueditor asp.net版本更改图片保存路径
  5. Android 开发笔记——对应用进行单元测试
  6. 四大跨平台的APP分析
  7. CompareValidator ASP控件
  8. 【USACO 2.4.5】分数化小数
  9. linux的du和df命令
  10. sql编程 1