解决报告

意甲冠军:

一定长度8000段染。寻求染色完成后,。。

思路:

区间问题用线段树。成段的更新区间。最后把全部的区间下压到叶子结点,统计叶子结点的颜色。

#include <iostream>
#include <cstring>
#include <cstdio> using namespace std;
int lz[32000],_hash[10000],color[10000],cnt;
void push_down(int rt)
{
if(lz[rt])
{
lz[rt*2]=lz[rt*2+1]=lz[rt];
lz[rt]=0;
}
}
void update(int rt,int l,int r,int ql,int qr,int v)
{
if(ql>r||qr<l)return ;
if(ql<=l&&r<=qr)
{
lz[rt]=v;
return ;
}
push_down(rt);
int mid=(l+r)/2;
update(rt*2,l,mid,ql,qr,v);
update(rt*2+1,mid+1,r,ql,qr,v);
}
void bin(int rt,int l,int r)
{
if(l==r)
{
color[cnt++]=lz[rt];
return ;
}
push_down(rt);
bin(rt*2,l,(l+r)/2);
bin(rt*2+1,(l+r)/2+1,r);
}
int main()
{
int n,m,i,j,ql,qr,a;
while(~scanf("%d",&n))
{
cnt=0;
memset(lz,0,sizeof(lz));
memset(_hash,0,sizeof(_hash));
m=8000;
int cmax=-1;
for(i=0; i<n; i++)
{
scanf("%d%d%d",&ql,&qr,&a);
update(1,1,m,ql+1,qr,a+1);
}
bin(1,1,m);
for(i=0; i<cnt;)
{
j=i+1;
_hash[color[i]]++;
while(color[j]==color[i]&&j<cnt)
j++;
i=j;
}
for(i=1; i<=m+1; i++)
{
if(_hash[i])
printf("%d %d\n",i-1,_hash[i]);
}
printf("\n");
}
return 0;
}

附手动随机数据

input:
10
2 4 6
4 6 2
1 9 3
4 6 2
1 20 3
2 4 3
6 7 1
3 7 9
4 6 9
2 6 4
10
43 54 8000
323 4342 123
234 2332 321
2 6 23
54 546 1
2843 8888 8000
3000 8000 0
23 4329 9
923 2323 8
2390 3293 1
10
1 34 8000
43 343 99
341 3414 8000
7999 8000 8000
344 345 1
434 3455 0
34 45 8000
43 56 45
56 64 0
898 4599 8000 output:
3 2
4 1
9 1 0 1
1 1
8 1
9 3
23 1 0 2
1 1
45 1
99 1
8000 5

Count the Colors


Time Limit: 2 Seconds      Memory Limit: 65536 KB


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


ZOJ1610_Count the Colors(段树/为段更新)的更多相关文章

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

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

  2. NYOJ 1068 ST(段树 为段更新+间隔总和)

    ST 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描写叙述 "麻雀"lengdan用随机数生成了后台数据.可是笨笨的他被妹纸的问题给难住了. .. 已知 ...

  3. poj-3468-A Simple Problem with Integers-线段树入门+区间更新

    You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...

  4. POJ 3264-Balanced Lineup(段树:单点更新,间隔查询)

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 34522   Accepted: 16224 ...

  5. ccnu-线段树联系-单点更新2-B

    B - 单点更新2 Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Des ...

  6. CodeForces 52C Circular RMQ(间隔周期段树,间隔更新,间隔总和)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://codeforces.com/problemset/problem/52/C You are g ...

  7. HDU 1698.Just a Hook-线段树(成段替换、输出总和tree[1])

    HDU1698.Just a Hook 这个题是最最基础的成段更新的线段数的题目,直接贴代码吧. 代码: #include<iostream> #include<cstring> ...

  8. POJ 3468.A Simple Problem with Integers-线段树(成段增减、区间查询求和)

    POJ 3468.A Simple Problem with Integers 这个题就是成段的增减以及区间查询求和操作. 代码: #include<iostream> #include& ...

  9. POJ 3225.Help with Intervals-线段树(成段替换、区间异或、简单hash)

    POJ3225.Help with Intervals 这个题就是对区间的各种操作,感觉这道题写的一点意思都没有,写到后面都不想写了,而且更神奇的是,自己的编译器连结果都输不出来,但是交上就过了,也是 ...

随机推荐

  1. addChildViewController transitionFromViewController nib storyboard

    本文记录addChildViewController由transitionFromViewController方法nib,storyboard的不同的效果. 在进行切换效果时,注意属于同一个story ...

  2. Android运用自己的标题栏

    Android程序的标题栏TitleBar区域很单调,如果想个性化一些可以通过下面的方法来为自己软件的标题定制一个layout布局文件,比如浏览器的标题栏,它包含了网站的Favicon,自定义的进度条 ...

  3. CMake入门(二)

    CMake入门(二) 最后更新日期:2014-04-25 by kagula 阅读前提:<CMake入门(一)>.Linux的基本操作 环境: Windows 8.1 64bit英文版.V ...

  4. Linux 编程学习笔记----过程管理和项目发展(在)

    转载请注明出处,http://blog.csdn.net/suool/article/details/38406211,谢谢. Linux进程存储结构和进程结构 可运行文件结构 例如以下图: 能够看出 ...

  5. Lua中的weak表——weak table(转)

    弱表(weak table)是一个很有意思的东西,像C++/Java等语言是没有的.弱表的定义是:A weak table is a table whose elements are weak ref ...

  6. 开源 自由 java CMS - FreeCMS1.9 评论管理

    项目地址:http://code.google.com/p/freecms/ 评论管理 1. 评论管理 从左側管理菜单点击评论管理进入. 2. 评论审核 选择须要审核的评论,然后点击"审核& ...

  7. php+sqlite 最佳web服务器

    1 wampserver   支持mysql.每次都启动mysql,可以手动停止.但是运行时有时会很慢. 放弃 2 APS绿色版(Apache+PHP+SQLite)  组件环境:Apache2.2. ...

  8. NGUI 3.5教程(四)Atlas和Sprite(制作图片button)

    Atlas是NGUI的图集.我的理解是:Atlas把你的一些零散的图片,合并成一张图.这样做的优点是,能够减少Draw Call.我不了解它的底层运作机制,我猜应该也是再行进DXT之类的纹理压缩,所以 ...

  9. ListView分页显示

    出在:http://blog.csdn.net/tu_bingbing/article/details/13275107         当ListView要显示的数据过多时,为了更快的响应用户,这个 ...

  10. JAVA对数据库进行操作,实现数据库中数据的插入,查询,更改,删除操作

    (—)通过mysql workbench 创建一个数据库,在这里命名为company,然后建一个tb_employee表 (二)以下是java代码对表tb_employee的操作 1 创建一个Empl ...