题目链接

题意:成段染色,初始为0,每次改变一个区间的颜色,求最后每种颜色分别有多少段。颜色按照从

小到大输出。

分析:改变了代码的风格,因为看了学长的博客。直接用数组,可以只是记录节点的编号,因为节点编号

确定了,则l,r也就确定了。

 #include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL __int64
#define lson l, mid, 2*rt
#define rson mid+1, r, 2*rt+1
const int maxn = +;
using namespace std;
int val[*maxn], num[maxn]; void pushdown(int rt) //如果没有更新,向下更新
{
if(val[rt]!=-)
{
val[*rt] = val[rt];
val[*rt+] = val[rt];
val[rt] = -;
}
}
void update(int ll, int rr, int c, int l, int r, int rt) //ll,rr代表要找的区间,不用减小了,一直都是这个
{
if(ll<=l && rr>=r) //如果当前节点的范围在 改变的节点的范围内就 改变
{
val[rt] = c;
return;
}
pushdown(rt);
int mid = (l+r)/;
if(ll<=mid) update(ll, rr, c, lson); //看这个左半区间内是否还有点
if(rr>mid) update(ll, rr, c, rson);
}
int query(int p, int l, int r, int rt)
{
if(l>p) return ;
if(r<p) return ;
if(p==l&&p==r) return val[rt];
if(p>=l && p<=r && val[rt]!=-) return val[rt];
int mid = (l+r)/;
return query(p, lson)+query(p, rson);
}
int main()
{
int i, n, l, r, c, x, pre;
while(~scanf("%d", &n))
{
memset(val, -, sizeof(val)); //相当于建树
memset(num, , sizeof(num));
while(n--)
{
scanf("%d%d%d", &l, &r, &c);
if(r- >= l)
update(l, r-, c, , , );
}
pre = -;
for(i = ; i <= ; i++) //查询的是区间00,11.。。
{
x = query(i, , , );
if(x!=pre) //如果不连续 就加上
{
pre = x;
if(x>=) num[x]++;
}
}
for(i = ; i <= ; i++)
{
if(num[i])
printf("%d %d\n", i, num[i]);
}
printf("\n");
}
return ;
}

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

  1. ZOJ 1610 Count the Colors (线段树成段更新)

    题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...

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

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

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

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

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

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

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

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

  6. 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. 这题 ...

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

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

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

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

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

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

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

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

随机推荐

  1. C#中Linq查询基本操作

    摘要:本文介绍Linq查询基本操作(查询关键字) - from 子句 - where 子句 - select子句 - group 子句 - into 子句 - orderby 子句 - join 子句 ...

  2. 【Leetcode】 - Single Number II

    Problem Discription: Suppose the array A has n items in which all of the numbers apear 3 times excep ...

  3. 使用HQL语句的按照参数名字查询数据库信息的时候 “=:”和参数之间不能存在空格,否则会报错

    问题描述: 今天在使用HQL的按照参数的名字查询数据库信息的时候报错如下: org.hibernate.QueryException: Space is not allowed after param ...

  4. AnkhSVN 安装

    为 visual Studio 2013 添加 AnkhSVN 步骤 到 https://ankhsvn.open.collab.net/downloads 下载 2.6x或以上 安装 AnkhSvn ...

  5. VB程序破解之API断点[bp __vbaVarTstEq]

    软件名称:风云足彩1.7软件大小:2.1M下载地址:http://free.ys168.com/?zhinengxuanhao软件保护:注册码编写软件:Microsoft Visual Basic 5 ...

  6. Chp14: Java

    1.finally keyword: finally keyword is used in association with a try/catch block and guarantees that ...

  7. Javascript通过className选择元素

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  8. chmod命令详细用法

    指令名称 : chmod 使用权限 : 所有使用者 使用方式 : chmod [-cfvR] [--help] [--version] mode file... 说明 : Linux/Unix 的档案 ...

  9. hdu 1753 大明A+B

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1753 容易出错的事例: 0.1 0.2 1.88 22.22 1 0.01 大概出错的几个点,做久了思维根 ...

  10. hadoop2.2.0集群搭建与部署

    原创文章,转载请注明: 转载自http://www.cnblogs.com/tovin/p/3818908.html 一.安装环境 1.系统环境 CentOS  6.4 2.集群机器节点ip 节点一i ...