题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个

分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以对于区间(L, R)我们只要让左端点+1即可按照正常的线段树操作来做。

#include<bits/stdc++.h>
#define lson l,   m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
 + ;
const int INF = 0x3f3f3f3f;
struct Query{ int L, R, val; };
], cnt[maxn], Rmax, ColorMax;
Query Q[maxn];

inline void PutDown(int rt)
{
    ){
        col[rt<<] = col[rt<<|] = col[rt];
        col[rt] = -;
    }
}

inline void update(int L, int R, int val, int l, int r, int rt)
{
    if(L <= l && r <= R){
        col[rt] = val;
        return ;
    }
    PutDown(rt);
    ;
    if(L <= m) update(L, R, val, lson);
    if(R >  m) update(L, R, val, rson);
}

int query(int pos, int l, int r, int rt)
{
    if(l == r) return col[rt];
    PutDown(rt);
    ;
    int ret;
    if(pos <= m) ret = query(pos, lson);
    if(pos >  m) ret = query(pos, rson);
    return ret;
}

int main(void)
{
    int paint;
    while(~scanf("%d", &paint)){

        Rmax = ColorMax = -INF;

        ; i<=paint; i++){
            scanf("%d %d %d", &Q[i].L, &Q[i].R, &Q[i].val);
            Q[i].L++;
            Rmax = max(Rmax, Q[i].R);///记录区间右端可以多大
            ColorMax = max(ColorMax, Q[i].val);///记录颜色的最大值
        }

        memset(col, -, sizeof(col));
        ; i<=paint; i++){
             < Q[i].R)///说明给出的是一个点,没有覆盖掉哪一段,不用更新
                update(Q[i].L, Q[i].R, Q[i].val, , Rmax, );
        }

        memset(cnt, , sizeof(cnt));
        ;
        ; i<=Rmax; i++){///查询区间内每个点的信息,用cnt[]数组来记录拥有的这些颜色占的段数
            , Rmax, );
            ) {last = -; continue;}///注意如果没有被染色,last要赋值成-1,不能直接continue
            if(color != last){
                cnt[color]++;
            }
            last = color;
        }

        ; i<=ColorMax; i++){
            ){
                printf("%d %d\n", i, cnt[i]);
            }
        }
        puts("");
    }
    ;
}

瞎 : query操作的时候由于有lazy tag所以需要PutDown,此题虽然不难但是如果独立写一个线段树并且AC估计能够发现自身的一些问题,注意实现细节....

ZOJ 1610 Count the Colors (线段树成段更新)的更多相关文章

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

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

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

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

  3. POJ 2777 Count Color (线段树成段更新+二进制思维)

    题目链接:http://poj.org/problem?id=2777 题意是有L个单位长的画板,T种颜色,O个操作.画板初始化为颜色1.操作C讲l到r单位之间的颜色变为c,操作P查询l到r单位之间的 ...

  4. ACM: Copying Data 线段树-成段更新-解题报告

    Copying Data Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description W ...

  5. Codeforces Round #149 (Div. 2) E. XOR on Segment (线段树成段更新+二进制)

    题目链接:http://codeforces.com/problemset/problem/242/E 给你n个数,m个操作,操作1是查询l到r之间的和,操作2是将l到r之间的每个数xor与x. 这题 ...

  6. hdu 4747【线段树-成段更新】.cpp

    题意: 给出一个有n个数的数列,并定义mex(l, r)表示数列中第l个元素到第r个元素中第一个没有出现的最小非负整数. 求出这个数列中所有mex的值. 思路: 可以看出对于一个数列,mex(r, r ...

  7. HDU1698_Just a Hook(线段树/成段更新)

    解题报告 题意: 原本区间1到n都是1,区间成段改变成一个值,求最后区间1到n的和. 思路: 线段树成段更新,区间去和. #include <iostream> #include < ...

  8. HDU 3577 Fast Arrangement ( 线段树 成段更新 区间最值 区间最大覆盖次数 )

    线段树成段更新+区间最值. 注意某人的乘车区间是[a, b-1],因为他在b站就下车了. #include <cstdio> #include <cstring> #inclu ...

  9. poj 3468 A Simple Problem with Integers 【线段树-成段更新】

    题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...

随机推荐

  1. [JavaScript] console.log只在查看时才会读取这个打印的对象,并把此刻相关属性和值显示出来

      /** * 写个函数解决console.log只在查看时才会读取这个打印的对象,并把此刻相关属性和值显示出来 * @param arg */ const log = function (...ar ...

  2. Shell 变量详解教程之位置变量与预定义变量

    Shell 变量分为3部分,分别是用户自定义变量.位置变量和预定义变量. 一.   自定义变量 那么,什么是变量呢?简单的说,就是让某一个特定字符串代表不固定的内容,用户定义的变量是最普通的Shell ...

  3. CentOS7 nginx 最简单的安装以及设置开机启动

    1. 下载tar包. 2. 解压缩tar包 3. 安装必须的部分 yum包 yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd ...

  4. 思考--PostgreSQL在与mysql的比较中稍微弱势项

    PostgreSQL在与mysql的比较中稍微弱势项: 1.都是堆表,没有所谓的聚集索引表,其实问题不大,聚集索引表也只是在使用聚集索引那些列有加速,而且pg也有聚集索引,只不过要定期重建. 2.mv ...

  5. Codeforces 1140F Extending Set of Points (线段树分治+并查集)

    这题有以下几个步骤 1.离线处理出每个点的作用范围 2.根据线段树得出作用范围 3.根据分治把每个范围内的点记录和处理 #include<bits/stdc++.h> using name ...

  6. ps -ef 和ps -aux的区别

    在 linux 显示进程的命令是ps ,常用的是 ps -ef,今天看到了还有一个ps -aux,查询了资料,这里总结一下 那么ps -ef 和ps -aux 有什么区别呢? 其实区别不是很大,这就要 ...

  7. python变量的内存管理

    python变量的内存管理 一.变量存在了哪里? 先让我们来看一段代码: height = 100 # 定义变量 # print(100) # print会自动帮你创建一个变量100,打印完之后,马上 ...

  8. VS Code Python 全新发布!Jupyter Notebook 原生支持终于来了!

    VS Code Python 全新发布!Jupyter Notebook 原生支持终于来了! 北京时间 2019 年 10 月 9 日,微软发布了全新的 VS Code Python 插件,带来了众多 ...

  9. 工作中常用到的JS验证

    Common.js // JavaScript Document // _ooOoo_ // o8888888o // 88" . "88 // (| -_- |) // O\ = ...

  10. notes-19-05-10

    一 mysql查找一个表中字段相同的数据  2019-05-10 15:51:03   多字段 ) 二 Referer的作用?2019-05-17 10:03:48 (来自网络) 1.防盗链我在www ...