有一块很长的画布,现在想在这块画布上画一些颜色,不过后面画的颜色会把前面画的颜色覆盖掉,现在想知道画完后这块画布的颜色分布,比如 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 ; } 

F - Count the Colors - zoj 1610(区间覆盖)的更多相关文章

  1. F - Count the Colors ZOJ - 1610 线段树染色(染区间映射)

    题意:给一段0-8000的线段染色 问最后 颜色x 有几段 题解:标准线段树  但是没有push_up  最后查询是单点按顺序查询每一个点 考虑过使用区间来维护不同的线段有多少种各色的线段  思路是 ...

  2. Count the Colors ZOJ - 1610 区间颜色覆盖

    #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> ...

  3. ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

  4. (线段树) Count the Colors --ZOJ --1610

    链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/F http://acm.zju.edu.cn/onli ...

  5. F - Count the Colors

    F - Count the Colors ZOJ - 1610   思路:调了一个小时,但是发现自己线段树木有写错,颜色统计出了错误.但是不明白自己颜色统计为什么错了. 求大佬指点迷津.思路很简单,就 ...

  6. zoj 1610 Count the Colors 线段树区间更新/暴力

    Count the Colors Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...

  7. 线段树专题—ZOJ1610 Count the Colors(涂区间,直接tag标记)

    Painting some colored segments on a line, some previously painted segments may be covered by some th ...

  8. ZOJ1610 Count the Colors —— 线段树 区间染色

    题目链接:https://vjudge.net/problem/ZOJ-1610 Painting some colored segments on a line, some previously p ...

  9. F - Count the Colors(线段树)

    Painting some colored segments on a line, some previously painted segments may be covered by some th ...

随机推荐

  1. C#学习第五天

    字符串的处理 string可作char的只读数组 下面这段字符表示访问每个字符: string myString="A string."; char myChar=myString ...

  2. Windows Azure上的Odoo(OpenERP)-2.在Ubuntu虚拟机上部署Odoo(OpenERP)

    创建虚拟机的步骤在这里就不再赘述了,请参考上一篇博文. 首先用下述命令将Ubuntu系统进行更新: 1. sudo apt-get update 2. sudo apt-get upgrade 3. ...

  3. input输入过滤js

    html部分使用方式 <input  onkeyup="usrNameSet(this)" /> 其它的自己可以随便调用 Js部分 //只能输入数字.字母.小数点.汉字 ...

  4. My.Ioc 代码示例——注册项的注销和更新

    当您需要从 Ioc 容器中注销/删除一个注册项的时候,您会怎么做呢? 有人曾经在 stackoverflow 上提问“如何从 Unity 中注销一个注册项”.对于这个问题,有人的回答是“有趣.你为什么 ...

  5. Android开发手记(15) 拨打电话和收发短信

    1.Intent简介 Android组价之间的通信,由Intent来协助完成.Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到 ...

  6. Linux基本权限

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

  7. 报错:ORA-02287: 此处不允许序号

    CREATE TABLE MY_TAB (N1 NUMBER(5),N2 DATE);          SELECT  * FROM MY_TAB;          CREATE SEQUENCE ...

  8. OC语法简写

    NSNumber [NSNumber numberWithInt:666] 等价于 @666 [NSNumber numberWithLongLong:666ll] 等价于 @666ll [NSNum ...

  9. java Enum 用法示例

    public enum MyEnum { Monday, Tuesday, Wednesday, Thursady, Friday, Saturday, Sunday; public static v ...

  10. Linux硬盘命名和安装分区

    硬盘命名: 硬盘命名基于文件,一般有如下文件方式: /dev/hda1 /dev/sdb3 具体含义如下: /dev:是所有设备文件存放的目录. hd和sd:他们是区别的前两个字母,代表该分区所在的设 ...