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

线段树区间更新,一段一段更新,并不是点

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int vis[];
int li,ri,w;
int pos[];
int ans[];
void pushdown(int node)
{
if(vis[node]!=-)
{
vis[node<<]=vis[node];
vis[node<<|]=vis[node];
vis[node]=-;
}
}
void update(int ll,int rr,int val,int l,int r,int node)
{
if(ll<=l && rr>=r)
{
vis[node]=val;
return ;
}
pushdown(node);
int mid=(l+r)>>;
if(ll<=mid) update(ll,rr,val,l,mid,node<<);
if(rr>mid) update(ll,rr,val,mid+,r,node<<|);
}
void query(int l,int r,int node)
{
if(vis[node]>=)
{
for(int i=l;i<=r;i++)
ans[i]=vis[node];
return ;
}
if(vis[node]==- && l!=r)
{
int mid=(l+r)>>;
query(l,mid,node<<);
query(mid+,r,node<<|);
}
}
int main()
{
int m;
while(scanf("%d",&m)!=EOF)
{
memset(vis,-,sizeof(vis));
memset(pos,,sizeof(pos));
memset(ans,-,sizeof(ans));
for(int i=;i<m;i++)
{
scanf("%d%d%d",&li,&ri,&w);
if(li>=ri) continue;
update(li+,ri,w,,,);
}
query(,,);
int i=;
while(i<)
{
int coo=ans[i],j=i+;
if(coo==-){i++;continue;}
while(j< && ans[j]==coo && ans[j]!=-)
{
j++;
}
pos[coo]++;
i=j;
}
for(int i=;i<;i++)
{
if(pos[i]) printf("%d %d\n",i,pos[i]);
}
printf("\n");
}
return ;
}

POJ 1610 Count the Colors的更多相关文章

  1. ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】

    任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...

  2. zoj 1610 Count the Colors

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610  Count the Colors Time Limit:2000MS   ...

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

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

  4. ZOJ 1610——Count the Colors——————【线段树区间替换、求不同颜色区间段数】

    Count the Colors Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

  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(线段树,区间覆盖,单点查询)

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

  7. ZOJ 1610 Count the Colors (线段树区间更新与统计)

    Painting some colored segments on a line, some previously painted segments may be covered by some th ...

  8. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

  9. ZOJ - 1610 Count the Colors(线段树区间更新,单点查询)

    1.给了每条线段的颜色,存在颜色覆盖,求表面上能够看到的颜色种类以及每种颜色的段数. 2.线段树区间更新,单点查询. 但是有点细节,比如: 输入: 2 0 1 1 2 3 1 输出: 1 2 这种情况 ...

随机推荐

  1. Fedora 17 安裝完全指南

    Fedora 17 关闭U盘自动mount gsettings set org.gnome.desktop.media-handling automount "false" gse ...

  2. 数据可视化之Processing【1】

    说Processing之前得先说一下数据可视化. 数据可视化--顾名思义.是关于数据之视觉表现形式的研究,将数据用其它方式表现出来,使之更直观, 更清晰,更easy分析和处理.常见的表达方式如word ...

  3. hibernate 或jpa 中使用 AliasToBeanResultTransformer 自定义类型转换ResultTransformer 下划线转驼峰

    jpa中使用 sql查询时,返回结果直接转为实体bean的实现, 需要自定义一个ResultTransformer,如下, import java.util.Arrays; import org.ap ...

  4. MyEclipse常见错误汇总,中英注释版(长期更新)

    No.1 当一条语句漏写分号时错误描述如下 Syntax error, insert ";" to complete Statement(语法错误:插入分号完成语句描述) No.2 ...

  5. Xshell高级后门完整分析报告

    Xshell高级后门完整分析报告 from:https://security.tencent.com/index.php/blog/msg/120 1. 前言 近日,Xshell官方发布公告称其软件中 ...

  6. Eval函数知识总结

    说道Json,我们先来聊聊eval 一.eval是什么?(解析器) eval是一个函数,看本质function  eval() { [native code] } 二.怎样使用eval? 语法:str ...

  7. [Swift] 随机数 | Random numbers

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  8. WHERE、ORDER BY、GROUP BY、HAVING语句解析(二十八)

    之前啊,我们提及到,对于update和delete,若不带where条件,则对所有记录都有效. 一.WHERE条件表达式 (1)对记录进行过滤,如果没有指定WHERE子句,则显示所有记录. (2)在W ...

  9. CSS之基于不同场景的垂直居中解决方案

    元素的水平居中,如果是一个行内元素,就对它的父元素应用 “text-align:center”: 如果是一个块级元素,就对它自身应用“margin:auto”. 垂直居中的几种场景以及实现方法: 一. ...

  10. net实现ping的方法

    class ServicePinger { private static readonly ILog log = LogManager.GetLogger(typeof(ServicePinger)) ...