描述
Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.
Your task is counting the segments of different colors you can see at last.

Input
The first line of each data set contains exactly one integer n, 1 <= n <= 8000, equal to the number of colored segments.
Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:
x1 x2 c
x1 and x2 indicate the left endpoint and right endpoint of the segment, c indicates the color of the segment.
All the numbers are in the range [0, 8000], and they are all integers.
Input may contain several data set, process to the end of file.

Output
Each line of the output should contain a color index that can be seen from the top, following the count of the segments of this color, they should be printed according to the color index.
If some color can't be seen, you shouldn't print it.
Print a blank line after every dataset.

Sample Input
5
0 4 4
0 3 1
3 4 2
0 2 2
0 2 3
4
0 1 1
3 4 1
1 3 2
1 3 1
6
0 1 0
1 2 1
2 3 1
1 2 0
2 3 0
1 2 1

Sample Output
1 1
2 1
3 1

1 1

0 2
1 1

题意

有一个线段,然后有n个操作,每个操作[X,Y]染成C颜色,最后问你线上的每个颜色有几段

题解

线段树区间更新延迟标记,最底层所有节点查询操作

代码

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int N=+; int lazy[N<<],dif[N<<],col[N],tot; void PushDown(int rt)
{
if(lazy[rt]!=-)
{
lazy[rt<<]=lazy[rt<<|]=lazy[rt];
lazy[rt]=-;
}
}
void Update(int L,int R,int C,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
lazy[rt]=C;
return;
}
int mid=(l+r)>>;
PushDown(rt);
if(L<=mid)Update(L,R,C,l,mid,rt<<);
if(R>mid)Update(L,R,C,mid+,r,rt<<|);
}
void Query(int l,int r,int rt)
{
if(l==r)
{
dif[tot++]=lazy[rt];
return;
}
int mid=(l+r)>>;
PushDown(rt);
Query(l,mid,rt<<);
Query(mid+,r,rt<<|);
}
int main()
{
int n,x,y,z;
while(scanf("%d",&n)!=EOF)
{
tot=;
memset(lazy,-,sizeof(lazy));
memset(col,,sizeof(col));
for(int i=;i<n;i++)
{
scanf("%d%d%d",&x,&y,&z);
Update(x+,y,z,,,);
}
Query(,,);
for(int i=;i<tot;)
{
if(dif[i]==-)
{
i++;continue;
}
int j=i;
while(dif[i]==dif[j])j++;
col[dif[i]]++;
i=j;
}
for(int i=;i<=;i++)
if(col[i])
printf("%d %d\n",i,col[i]);
printf("\n");
}
return ;
}

ZOJ 1610 Count the Color(线段树区间更新)的更多相关文章

  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. ZOJ 1610.Count the Colors-线段树(区间染色、区间更新、单点查询)-有点小坑(染色片段)

    ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting s ...

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

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

  5. ZOJ 5638——Prime Query——————【线段树区间更新,区间查询,单点更新】

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  6. POJ2777 Count Color 线段树区间更新

    题目描写叙述: 长度为L个单位的画板,有T种不同的颜料.现要求按序做O个操作,操作分两种: 1."C A B C",即将A到B之间的区域涂上颜色C 2."P A B&qu ...

  7. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

  8. ZOJ - 1610 Count the Colors(线段树区间更新,单点查询)

    1.给了每条线段的颜色,存在颜色覆盖,求表面上能够看到的颜色种类以及每种颜色的段数. 2.线段树区间更新,单点查询. 但是有点细节,比如: 输入: 2 0 1 1 2 3 1 输出: 1 2 这种情况 ...

  9. 【POJ 2777】 Count Color(线段树区间更新与查询)

    [POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4094 ...

随机推荐

  1. linux 源码编译php的参数

    ./configure --prefix=/usr/local/php-5.3.5 --with-config-file-path=/usr/local/php-5.3.5/etc --with-co ...

  2. NetBeans 8以后版本无法连接git服务器

    因为目前的git服务器的密钥加密基本都是256位的,而NetBeans带的jre环境的加密限制在基本的128位加密,从而导致无法和git服务器通信 解决办法 下载Java Cryptography E ...

  3. day28-面相对象的特殊成员、内置函数

    1. isinstance与issubclass 1.1.isinstance(obj,cls) 检查obj是否是类cls的对象,或者是类cls的子类的对象 class A: pass class B ...

  4. canal 入门

    参考文章:Canal - 安装   https://www.aliyun.com/jiaocheng/1131288.html?spm=5176.100033.2.7.7b422237XAirIe 前 ...

  5. mui集成百度ECharts的统计图表以及清空释放图表

    echarts官网地址: http://echarts.baidu.com/index.html 更换主题颜色: // 图表清空------------------- mychart.clear(); ...

  6. jinjia

    https://www.cnblogs.com/dachenzi/p/8242713.html

  7. linux 时间相关的一些总结

    仅作为内核代码中时间管理模块的笔记,3.10内核,很乱,不喜勿喷. 先有time,后有timer. 常用的time结构有哪些?除了大名鼎鼎的jiffies和jiffies64之外,还有常用的一些结构如 ...

  8. 【362】python 正则表达式

    参考:正则表达式 - 廖雪峰 参考:Python3 正则表达式 - 菜鸟教程 参考:正则表达式 - 教程 re.match 尝试从字符串的起始位置匹配一个模式,如果不是起始位置匹配成功的话,match ...

  9. avalon2学习教程01

    经过难苦奋战,avalon2终于面世了.这花了大半年时间,其中1.6还胎死腹中.长达半年没有产出,我都担心自己会被裁掉…… avalon2许多API与1.4.×保持一致,当然也添加了一些1.5的功能, ...

  10. Aop 中 JoinPoint等对象的用法Api

    @Aspect 定义类为切入类 @Pointcut 声明一个切入策略供 @Before @After @ Around @ AfterReturning选择 @Before 被切入方法执行前执行 @A ...