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

题解:各种错。。。最终发现还是要插a+1,b才可以,因为是颜色段,并不是点,还有,那个n是n条线段,所以查找和建树均要是8000内建,否则会wa;

思路:-1代笔多色,0代表无色;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define SD(x,y) scanf("%lf%lf",&x,&y)
#define P_ printf(" ")
#define ll root<<1
#define rr root<<1|1
#define lson ll,l,mid
#define rson rr,mid+1,r
#define V(x) tree[x]
typedef long long LL;
const int MAXN=8010;
int color[MAXN];
int temp;
int tree[MAXN<<2];
void pushdown(int root){
if(V(root)>0){
V(ll)=V(root);
V(rr)=V(root);
V(root)=-1;
}
}
void build(int root,int l,int r){
int mid=(l+r)>>1;
V(root)=0;
if(l==r)return;
build(lson);build(rson);
}
void update(int root,int l,int r,int A,int B,int v){
if(l>=A&&r<=B){
V(root)=v;
return;
}
int mid=(l+r)>>1;
pushdown(root);
if(mid>=A)update(lson,A,B,v);
if(mid<B)update(rson,A,B,v);
V(root)=-1;
}
void query(int root,int l,int r){
int mid=(l+r)>>1;
if(temp==V(root))return;
if(!V(root)){
temp=0;return;
}
if(V(root)!=-1){
if(temp!=V(root)){
temp=V(root);
color[temp]++;
return;
}
return;
}
if(l==r)return;
query(lson);
query(rson);
}
int main(){
int n;
while(~scanf("%d",&n)){
mem(color,0);
build(1,1,8000);
int a,b,c;
int t=n;
while(t--){
scanf("%d%d%d",&a,&b,&c);
update(1,1,8000,a+1,b,c+1);
}
query(1,1,8000);
for(int i=1;i<=8001;i++){
if(color[i])printf("%d %d\n",i-1,color[i]);
}puts("");
}
return 0;
}

  

Count the Colors(线段树,找颜色段条数)的更多相关文章

  1. W同学的新画板 QDUOJ 线段树 区间颜色段数

    W同学的新画板 QDUOJ 线段树 区间颜色段数 原题链接 题意 W同学在每天的刻苦学习完成功课之余,都会去找一些有趣的事情来放松自己:恰巧今天他收到了朋友送给他的一套画板,于是他立刻拆开了包装,拿出 ...

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

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

  3. [ZOJ1610]Count the Colors(线段树,区间染色,单点查询)

    题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=1610 题意:给一个长8000的绳子,向上染色.一共有n段被染色,问染 ...

  4. zoj 1610 Count the Colors 线段树区间更新/暴力

    Count the Colors Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...

  5. ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

  6. ZOJ-1610 Count the Colors ( 线段树 )

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Description Painting some co ...

  7. ZOJ1610 Count the Colors —— 线段树 区间染色

    题目链接:https://vjudge.net/problem/ZOJ-1610 Painting some colored segments on a line, some previously p ...

  8. Count the Colors 线段树

    题目 参考博客地址 题意: n范围[1,8000] ,  li 和 ri 的范围[0,8000].  n个操作,每个操作是把 [li , ri]内的点修改成一个颜色c. n个操作过后,按颜色从小到大 ...

  9. 【POJ 2777】 Count Color(线段树区间更新与查询)

    [POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4094 ...

随机推荐

  1. python 自学笔记(四) 列表

    有几天没有更新博客了,毕竟是自学,最近事情确实比较多,有时候想学的时候反而没时间,到有时间的时候反而不想学.以后得想办法改掉这个缺点,只要有时间就要学习自己想学的东西,希望自学的同学能和我共同交流,其 ...

  2. Criteria 和 DetachedCriteria的区别与使用(转)

    转自:http://javapub.iteye.com/blog/1149709 Criteria 和 DetachedCriteria 的主要区别在于创建的形式不一样, Criteria 是在线的, ...

  3. getHibernateTemplate()和getSession()的区别

    自动生成hibernate配置文件的时候,会在dao层用到getSession()方法来操作数据库记录,但是他还有个方法getHibernateTemplate(),这两个方法究竟有什么区别呢? 1. ...

  4. 【原】win7下调整分区

    由于装系统时硬盘分区极度不合理,导致现在装一些比较大的开发软件根本不能装,但是又不想重装系统调整分区,而且还不想让已有的文件受到一点伤害,毕竟数据无价啊.几番搜索后,发现了一款比较好用的硬盘管理软件  ...

  5. uva 10972 RevolC FaeLoN cdoj 方老师和农场

    //自己写的第一发tarjan 解:先进行双连通分解并缩点,分解后一定是一颗树,设叶节点个数为n那么答案就是(n+1)/2 关于双连通分量求解:在跑tarjan时判断每个点连向父节点的边是否是桥,如果 ...

  6. 【Python】iichats —— 命令行下的局域网聊天程序

    转载请声明出处:http://www.cnblogs.com/kevince/p/3941728.html   ——By Kevince ii系列工具第三弹,命令行下的局域网聊天程序 原理: 程序启动 ...

  7. How to convert string to wstring?

    How to convert string to wstring? - Codejie's C++ Space - C++博客     How to convert string to wstring ...

  8. [Phonegap+Sencha Touch] 移动开发36 Phonegap/Cordova项目的图标和启动画面(splashscreen)配置

    原文地址:http://blog.csdn.net/lovelyelfpop/article/details/40780111 Phonegap/Cordova项目中的config.xml文件.里面配 ...

  9. CSS3实战开发 表单发光特效实战开发

    首先,我们先准备好html代码: <!doctype html> <html> <head> <meta charset="utf-8"& ...

  10. C#中T的用法

    之前一直用List<T>这样的泛型,看到过有些参数类型也可以直接用T的,觉得很好用,但是一直用不了,现在才发现原来是少加了<T> public T getdate<T&g ...