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 ...
随机推荐
- 我的母校zbvc试做
一.观察分析页面布局 可以从上至下分为6大部分 logo栏 menu菜单栏 slide幻灯片 news新闻区域 other其他 bottom底部 二.logo 分为三部分 ①左侧logo ②中间log ...
- 深度学习原理与框架-RNN网络架构-RNN网络 1.RNN的前向传播 2.RNN的反向传播
对于神经网络而言,每一个样本的输入与输入直接都是独立的,即预测的结果之间并没有联系 而对于RNN而言:不仅仅是有当前的输入,而且上一层的隐藏层也将进行输入,用于进行结果的预测.因此每一个输入都与之前的 ...
- day43-socketserver
基于tcp的套接字,关键就是两个循环,一个链接循环,一个通信循环 socketserver模块中分两大类:server类(解决链接问题)和request类(解决通信问题) server类: reque ...
- day31-软件开发规范
一.为什么要规范软件开发? 1.1 为什么要有规范软件开发 你现在包括之前写的一些程序,所谓的'项目',都是在一个py文件下完成的,代码量撑死也就几百行,你认为没问题,挺好.但是真正的后端开发的项目, ...
- eclipse 导出 javadoc
项目右键Export ->java/javadoc -> 选择要导出的项目,javadoc.exe,存放路径,导出的级别(private可导出全部) ->在VM option中加入- ...
- jquery接触初级-----juqery DOM操作实例,动态图片显示
1. 要求:对一个a标签元素,当鼠标操作,移入时,显示a标签title属性的信息,鼠标移出时,隐藏a标签属性的title属性信息 a 标签本身的title 属性具有自我显示的特性,但是这个特性比较慢, ...
- python 叠加装饰器详解
def out1(func1): #7.func1=in2的内存地址,就是in2 print('out1') def in1(): #8.调用函数index() 因为函数在in1里,所以首先运行in1 ...
- centos7,进程最大打开文件数 too many open files错误
遇到一问题,tomcat最近发生几次异常,查看日志,发现一直报 too many open files,熟悉的同学都知道这是用户打开文件数过多导致的, 再用命令ls /proc/20861/fd/ | ...
- String特殊值的判断方式
对String的特殊值的判断上,除了要关注是否为null,还要关注是否是空字符串. 经常处理的时候直接判断是否为Null就好了,这样很容易出现问题: if(null!=str) { //not goo ...
- ReactiveX 学习笔记(15)使用 Rx.NET + Json.NET 调用 REST API
JSON : Placeholder JSON : Placeholder (https://jsonplaceholder.typicode.com/) 是一个用于测试的 REST API 网站. ...