题目链接

题意:成段染色,初始为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. Get current time and date on Android

    You could use: Calendar c =Calendar.getInstance();int seconds = c.get(Calendar.SECOND); There are pl ...

  2. 最火的.NET开源项目(转)

    综合类 微软企业库 微软官方出品,是为了协助开发商解决企业级应用开发过程中所面临的一系列共性的问题, 如安全(Security).日志(Logging).数据访问(Data Access).配置管理( ...

  3. Careercup - Google面试题 - 4557716425015296

    2014-05-03 21:57 题目链接 原题: Many sticks with length, every time combine two, the cost is the sum of tw ...

  4. FFmpeg在Android上的移植之第一步

    http://blog.sina.com.cn/s/blog_69a04cf40100x1fr.html 从事多媒体软件开发的人几乎没有不知道FFmpeg的,很多视频播放器都是基于FFmpeg开发的. ...

  5. Java 集合类(一)

    今天我们先讲一下Collection: Collection和Collections的区别: java.util.Collection是一种java集合接口,它提供了对集合对象的基本操作通用接口方法, ...

  6. 【POJ】【1067】取石子游戏

    博弈论 这个是博弈游戏中的Wythoff博弈: 以下为我的代码: //POJ 1067 #include<cmath> #include<cstdio> #include< ...

  7. IOS 中的MVC设计模式

  8. 2014多校第一场J题 || HDU 4870 Rating(DP || 高斯消元)

    题目链接 题意 :小女孩注册了两个比赛的帐号,初始分值都为0,每做一次比赛如果排名在前两百名,rating涨50,否则降100,告诉你她每次比赛在前两百名的概率p,如果她每次做题都用两个账号中分数低的 ...

  9. C# get set方法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. 00 - Oracle体系结构课程内容

    1.导论 自己把本书内容分为几个部分, (1)体系结构,(2)并发控制和事务,(3)物理存储, (4)其他. 嗯,拿到一个新的数据库,我们也要从这几个方面去认识它.   2.体系结构 3.Oracle ...