ZOJ 1610 Count the Color(线段树区间更新)
描述
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(线段树区间更新)的更多相关文章
- zoj 1610 Count the Colors 线段树区间更新/暴力
Count the Colors Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...
- ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- ZOJ 1610.Count the Colors-线段树(区间染色、区间更新、单点查询)-有点小坑(染色片段)
ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting s ...
- ZOJ 1610 Count the Colors (线段树成段更新)
题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...
- ZOJ 5638——Prime Query——————【线段树区间更新,区间查询,单点更新】
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a s ...
- POJ2777 Count Color 线段树区间更新
题目描写叙述: 长度为L个单位的画板,有T种不同的颜料.现要求按序做O个操作,操作分两种: 1."C A B C",即将A到B之间的区域涂上颜色C 2."P A B&qu ...
- ZOJ 1610 Count the Colors (线段树区间更新)
题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
- ZOJ - 1610 Count the Colors(线段树区间更新,单点查询)
1.给了每条线段的颜色,存在颜色覆盖,求表面上能够看到的颜色种类以及每种颜色的段数. 2.线段树区间更新,单点查询. 但是有点细节,比如: 输入: 2 0 1 1 2 3 1 输出: 1 2 这种情况 ...
- 【POJ 2777】 Count Color(线段树区间更新与查询)
[POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4094 ...
随机推荐
- 机器学习进阶-图像特征harris-角点检测 1.cv2.cornerHarris(进行角点检测)
1.cv2.cornerHarris(gray, 2, 3, 0.04) # 找出图像中的角点 参数说明:gray表示输入的灰度图,2表示进行角点移动的卷积框,3表示后续进行梯度计算的sobel算子 ...
- 09-清除默认格式 reset.css
根据需要选择和裁剪后使用,以减少代码量 /* 清除内外边距 */ body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, /* structural elem ...
- day07-while,for循环
1.循环语句 Python提供了for循环和while循环while在给定的判断条件为 true 时执行循环体,否则退出循环体.for重复执行语句嵌套循环可以在while循环体中嵌套for.while ...
- SRM-相关资料路径
SRM采购管理平台功能介绍 https://wenku.baidu.com/view/b05cff5930b765ce0508763231126edb6f1a763c.html https://wen ...
- 用ADO操作数据库的方法步骤(ZT)
http://www.cppblog.com/changshoumeng/articles/113437.html 学习ADO时总结的一些经验 用ADO操作数据库的方法步骤 ADO接口简介 ADO库包 ...
- jquery Load方法的重要点
一个非常重要而且很容易忽视的问题就是:你是否load进了你必须load的元素,是否有的没有load进来,打开firebug查看一下
- openwrt多wan限上下行速脚本,基于qosv4,imq模块替换成ifb模块[ZT]
转自: http://www.right.com.cn/forum/thread-169414-1-1.html ,本人未经测试,转来自已备用 由于树莓派2装openwrt官方没有imq模块, 好像说 ...
- HashMap 实现总结
Entry类中需包含键值的hash值,防止resize时的重复计算: Map容量为2的整幂,可使用位操作取代取余操作提高效率: resize时需要将原table的桶内数据置null,利于垃圾回收: h ...
- C# 获取汉字转拼音缩写-简写,不是全拼
///<summary> /// 汉字转拼音缩写 /// Code By ] -'\0')); if ( i <0xB0A1) return"*" ...
- quartz整合spring框架service层对象注入为null解决方案
Job实现类代码 package cn.itcast.quartz; import org.quartz.Job; import org.quartz.JobExecutionContext; imp ...