解决报告

意甲冠军:

一定长度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. HashMap的遍历和排序

    1.HashMap的遍历 package com.sheepmu; import java.util.HashMap; import java.util.Iterator; import java.u ...

  2. SICP 锻炼 (2.15)解决摘要:深入思考间隔误差

    SICP 2.15 是接着 题目 2.14 的, 题目 2.14中提到了Alyssa设计的区间计算模块在并联电阻计算时会出现故障,这个问题是Lem发现的. 接着,一个叫Eva的人也发现了这个问题.同一 ...

  3. c#错误捕获如何定位到某一行?

    e.ToString()在调试版本的程序(并且有pdb文件)的情况下会输出源代码行.

  4. 举例说, Decorator模式(Decorator Pattern)

    前言    在食品工业中的装饰图案具有比较广泛的应用,大多数的两个图案和在网上的例子饮食相关的,一旦被称为电影的手表,点咖啡要加糖要加奶昔要加这加那的时候.感觉好有派~好高大上啊~.为啥我在小卖部都是 ...

  5. OutputCache说明

    当用户访问该页面,整个页面会server存储在内存中,因此,该页面缓存.当用户再次访问该页面,页面不会再次运行数据操作,页面首先检查server中是否存在缓存.假设缓存存在,则直接从缓存中获取页面信息 ...

  6. 离PACKET_INp获取信息acket data

         于Floodlight模块假设要packet in消息,就对对应的消息类型进行监听就可以.然后在receive方法中就能够操纵这个上传上来的packet_in.      关键代码:   E ...

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

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

  8. Android异步操作总结

    Android中常常会有一些操作比方网络请求,文件读写.数据库操作.比較耗时,我们须要将其放在非UI线程去处理.此时.我们须要处理任务前后UI的变化和交互.我们须要通过类似js中异步请求处理,这里总结 ...

  9. Android - 分享内容 - 接收其他APP的内容

    就象程序可以发送数据给其他程序,所以也可以接收其他程序的数据.想一下用户如何和程序交互,以及想从其他程序接收什么样类型的数据.例如,一个社交程序可能对接收其他程序的文字(比如有趣的网址)感兴趣.Goo ...

  10. Chapter 1 Securing Your Server and Network(5):使用SSL加密会话

    原文:Chapter 1 Securing Your Server and Network(5):使用SSL加密会话 原文出处:http://blog.csdn.net/dba_huangzj/art ...