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 ...
随机推荐
- 使用linux的shell脚本实现在当前行重复动态显示时间等字符串信息(不另起新行)
###本脚本在Suse11sp2当中验证正确 #!/bin/sh )) do echo -ne "\r$(date)" sleep 0.3 done ###关键在 echo 的 & ...
- subsets 回溯 给定集合,枚举子集。元素不重复
这个回溯感觉掌握的有些熟练了. 两种方式,递归和循环. 感觉就是套框架了. /** * Return an array of arrays of size *returnSize. * The siz ...
- python multithread task_done
queue.task_done()用在queue消费者中,在queue.get()调用之后调用queue.task_done()用于通知队列已经完成了工作,使queue.join()知道任务已经完成. ...
- linux suse 3.0.101的一次中断暴增的排查
本文相关背景知识可以在:http://man7.org/linux/man-pages/man5/proc.5.html?spm=5176.100239.blogcont6047.8.ImCGpr 看 ...
- linux 2.6.32.220的一个crash记录
有同事分析一个crash,我参与了分析,记录如下,供遇到相同crash的兄弟参考: crash> bt PID: TASK: ffff881723ce8080 CPU: COMMAND: &qu ...
- 一小段测试atof的代码
#include <stdio.h> //#include <stdlib.h> double a=0; int main(int argc, char *argv[]) { ...
- 转:jquery操作元素的css样式(获取、修改等等)
//1.获取和设置样式 $("#tow").attr("class")获取ID为tow的class属性 $("#two").attr(&qu ...
- Oracle数据库安装指南
文档使用声明 1.安装指导仅限测试环境(非生产环境)安装使用,生产环境oracle数据库建议按公司要求安装. 安装环境 1.SuSE10/SuSE11(64位) + Oracle11gR2 工具和安装 ...
- HttpURLConnection 添加代理
//创建代理服务器 Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("www.proxyaddress.com& ...
- platform 系统是windows还是liunx
import platform # 判断当前代码运行的系统是windows还是liunx print(platform.architecture()) print(platform.platform( ...