解决报告

意甲冠军:

一定长度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. OCP-1Z0-051-名称解析-文章7称号

    7. Which two  statements are true regarding the USING and ON clauses in table joins? (Choose two.) A ...

  2. Django操作model时刻,一个错误:AttributeError:’ProgrammingError’ object has no attribute ‘__traceback__’

    原因:在Django项目下对应的应用以下的models.py配置的model(也就是class)没有创建成对应的表. 这是怎么回事呢? 首先,将models.py里面的model创建成相应的数据库表的 ...

  3. BackTrack5 (BT5)无线password破解教程WPA/WPA2-PSK无线password皴

    昨天公布了BackTrack5 (BT5)无线weppassword破解教程之minidwep-gtk破解法一文,对BT5下破解wep无线password的简单方法做了介绍,今天奶牛为朋友们介绍下怎样 ...

  4. 重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView

    原文:重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView [源码下载] 重新想象 Windows 8 Store Apps (11) - ...

  5. 【源代码】TreeMap源代码剖析

    注:下面源代码基于jdk1.7.0_11 之前介绍了一系列Map集合中的详细实现类,包含HashMap,HashTable,LinkedHashMap.这三个类都是基于哈希表实现的,今天我们介绍还有一 ...

  6. 设计Mysql索引的原则

    1. 搜索的索引列,不一定是所要选择的列.换句话说,最适合索引的列是出如今WHERE 子句中的列,或连接子句中指定的列,而不是出如今SELECT keyword后的选择列表中的列. 2. 使用惟一索引 ...

  7. 《SAS编程和数据挖掘商业案例》学习笔记# 19

    继续<SAS编程与数据挖掘商业案例>学习笔记,本文側重数据处理实践.包含:HASH对象.自己定义format.以及功能强大的正則表達式 一:HASH对象 Hash对象又称散列表,是依据关键 ...

  8. 如何使用junit4写单元测试用例(转)

    JUnit4是JUnit框架有史以来的最大改进,其主要目标便是利用Java5的Annotation特性简化测试用例的编写. 先 简单解释一下什么是Annotation,这个单词一般是翻译成元数据.元数 ...

  9. poj 2408 Anagram Groups(hash)

    id=2408" target="_blank" style="">题目链接:poj 2408 Anagram Groups 题目大意:给定若干 ...

  10. Windows8和Windows Phone应用开发主题编码汇总

    原文:Windows8和Windows Phone应用开发主题编码汇总 在Windows 8和Windows Phone应用开发中经常需要自定义一些Windows Store应用风格主题,下面列举一些 ...