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

    (redis的安装, 配置, 登陆等基础不再多说, 网上很多资料的, 这里只说个人对redis多实例的理解与配置) 我自己使用的redis版本是 2.8.13, 环境是 ubuntu 个人对多实例的理 ...

  2. 怎样找Android里自带的数据库?

    首先先让它显示出来. 窗口window下的Show View 下的File Explorer(other里), 这时File Explorer窗口 就会显示出来,下一步我们找到data下的data,然 ...

  3. centos7.2下安装mysql5.7,使用rpm包安装

    0.环境 本文操作系统: CentOS 7.2.1511 x86_64 MySQL 版本: 5.7.16 1.卸载系统自带的 mariadb-lib[root@centos-linux ~]# rpm ...

  4. html02表格的使用

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  5. codevs 4909 寂寞的堆(写的好丑0.0)

    #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #defin ...

  6. http2.0

    HTTP2.0性能增强的核心:二进制分帧 HTTP 2.0最大的特点: 不会改动HTTP 的语义,HTTP 方法.状态码.URI 及首部字段,等等这些核心概念上一如往常,却能致力于突破上一代标准的性能 ...

  7. js求字符长度

    </script> <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

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

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

  9. 模拟vector

    实现了vector的模板,insert, erase, push_back, iterator #include<iostream> #include<string.h> #i ...

  10. PAT-1041 Be Unique

    Being unique is so important to people on Mars that even their lottery is designed in a unique way. ...