有一块很长的画布,现在想在这块画布上画一些颜色,不过后面画的颜色会把前面画的颜色覆盖掉,现在想知道画完后这块画布的颜色分布,比如 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. codevs 2495 水叮当的舞步IDA*

    /* 比较简单的A* 估价函数很简单就是除了左上角的联通快之外的不同的个数 加上迭代 好像答案最多在16步之内出解 这样裸裸的交上去是50分 在考虑剪枝 每个选颜色的时候一定是选左上角联通快附近的颜色 ...

  2. VB几种函数参数传递方法,Variant,数组,Optional,ParamArray

    VB几种函数参数传递方法,Variant,数组,Optional,ParamArray 一) 过程的参数被缺省为具有 Variant 数据类型. 1)ByRef按 地址传递参数在 VB 中是缺省的 按 ...

  3. HDU3480

    题意:给你n个数,然后让你分成m个集合,每个集合有一个值(最大值减最小值,然后平方),求整个集合的可能最小值. 思路:因为每个集合里的值只和最大和最小值有关,所以很容易想到先排序,然后用DP可求得解, ...

  4. Android 巧妙实现图片和文字布局

    之前写过一个博客是关于实现图片和文字左右或者上下布局的方法, 下面是博客的主要内容: 布局文件很简单,用来展示RadioButton的使用方法. 1 <?xml version="1. ...

  5. 顶部图片放大回弹效果Scrollview ---- 各应用中常见的自定义View 解析

    原理并不难.  代码量也不大.  非常简洁 .  先来个效果图 再上一波代码. public class SpecialScrollView extends ScrollView implements ...

  6. 64位操作系统下IIS报“试图加载格式不正确的程序”错误

    缘由:在64位操作系统下IIS发布32位的项目,报“项目依赖的dll无法读取,试图加载格式不正确的程序”错误. 原因:程序集之间的通讯要么全是64位环境下的,要么全是32位环境下的.不能混编访问.不然 ...

  7. JavaScript--机选双色球

    <!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. C++ 数组作为函数参数时,传递数组大小的方法

    废话不多说,先上错误示范: void fun(int arr[arr_num]) { // ... } int main() { // ... int *arr = new int[10]; fun( ...

  9. 解决Mac上Android开发时adb连接不到手机问题

    今天在Mac OS上进行Android开发的时候,打开eclipse连接不到手机MX4问题 1. 插入手机打开 Terminal,输入 system_profiler  SPUSBDataType 2 ...

  10. jQuery 做好七件事帮你提升jQuery的性能

    1. Append Outside of Loops 凡是触及到DOM都是有代价的.如果你向DOM当中附加大量的元素,你会想一次性将它们全部附加进来,而不是分多次进行.当在循环当中附加元素就会产生一个 ...