G. Count the Colors

Time Limit: 2000ms
Memory Limit: 65536KB

64-bit integer IO format: %lld      Java class name: Main

 
 
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

 解题:线段树。。。比较奇葩的线段树,此树的叶子节点必须是一个长度为1的线段,而不是我通常所写的那种叶子节点就是一个点的那种。
 
[0,4]
[0,2][2,4]
[0,1][1,2][2,3][3,4]
是这种线段树。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#define LL long long
#define INF 0x3f3f3f
using namespace std;
const int maxn = ;
struct node {
int lt,rt,color;
} tree[maxn<<];
int col[maxn],temp;
void build(int lt,int rt,int v) {
int mid = (lt+rt)>>;
tree[v].lt = lt;
tree[v].rt = rt;
tree[v].color = -;
if(lt+ == rt) return;
build(lt,mid,v<<);
build(mid,rt,v<<|);
}
void update(int lt,int rt,int c,int v) {
if(lt == rt || tree[v].color == c) return;
if(tree[v].lt >= lt && tree[v].rt <= rt) {
tree[v].color = c;
return;
}
if(tree[v].color >= ) {
tree[v<<].color = tree[v<<|].color = tree[v].color;
tree[v].color = -;
}
int mid = (tree[v].lt+tree[v].rt)>>;
if(rt <= mid) {
update(lt,rt,c,v<<);
} else if(lt >= mid) {
update(lt,rt,c,v<<|);
} else {
update(lt,mid,c,v<<);
update(mid,rt,c,v<<|);
}
tree[v].color = -;
}
void query(int v) {
if(tree[v].color == -) {
temp = -;
return;
}
if(tree[v].color != -) {
if(tree[v].color != temp) {
temp = tree[v].color;
col[temp]++;
}
return;
}
if(tree[v].lt+ != tree[v].rt) {
query(v<<);
query(v<<|);
}
}
int main() {
int n,i,j,x,y,c,mx;
while(~scanf("%d",&n)) {
build(,,);
memset(col,,sizeof(col));
mx = ;
for(i = ; i < n; i++) {
scanf("%d%d%d",&x,&y,&c);
update(x,y,c,);
if(c > mx) mx = c;
}
temp = -;
query();
for(i = ; i <= mx; i++)
if(col[i]) printf("%d %d\n",i,col[i]);
printf("\n");
}
return ;
}
 

xtu数据结构 G. Count the Colors的更多相关文章

  1. Count the Colors(线段树染色)

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

  2. zoj 1610 Count the Colors

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

  3. Count the Colors(线段树,找颜色段条数)

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

  4. Count the Colors

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

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

    链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/F http://acm.zju.edu.cn/onli ...

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

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

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

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

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

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

  9. zoj 1610 Count the Colors 【区间覆盖 求染色段】

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

随机推荐

  1. asp.net,监听输入框值的即时变化onpropertychange、oninput

    作者:自由天堂发布站点:WEB六零零 网页设计制作原文地址:http://www.web600.net/html/editor/JavaScript/201001131529.html 要达到的效果 ...

  2. 关于Winform控件调用插入点(光标)的用法

    我们自定义控件中可能会有一些光标的使用,比如插入文字和图片提示,下面是调用WIN32 API的光标用法 Winform控件调用插入点的用法 // 导入处理光标的 Windows 32 位 API // ...

  3. Java编程基础-面向对象(下)

    一.抽象类 1.引入:当定义一个类时,常常需要定义一些方法来描述该类的行为特征,但有时这些方法的实现方式是无法确定的.Java允许在定义方法时不写方法体,不包含方法体的方法为抽象方法,抽象方法必须使用 ...

  4. 关于React的赋值与调用方法

    #关于React的赋值与调用方法 比如调用方法的时候我们可以这样来使用closeFrm() <div className = "infoFrm_close" onMouseO ...

  5. GraphicsMagick安装&make命令使用

    0.0本过程为GraphicsMagick Linux版安装,通过典型的make编译安装. 未了支持png和jpg格式,首先请安装依赖.执行 yum install -y libpng-devel y ...

  6. IOS与android

    Android和iOS那个好?应该先往哪个上面投入资源?多次被人问到此类问题,笔者刚好自己的项目也需要考虑iOS版本.就索性进行了一番调研,于是有了本文(本次不讨论越狱的iOS) 首先从情感上,你喜欢 ...

  7. sublime快捷键mark

    Ctrl+D 选词 (反复按快捷键,即可继续向下同时选中下一个相同的文本进行同时编辑)Ctrl+G 跳转到相应的行Ctrl+J 合并行(已选择需要合并的多行时)Ctrl+L 选择整行(按住-继续选择下 ...

  8. angulajs中引用chart.js做报表,修改线条样式

    目前还有个问题,在手机上看,当折线y轴值超过1000,会有点问题 1.下载chart js,可以用bower 命令下载 http://www.chartjs.org/docs/#line-chart- ...

  9. vijos 1164 曹冲养猪

    描述 自从曹冲搞定了大象以后,曹操就开始捉摸让儿子干些事业,于是派他到中原养猪场养猪,可是曹冲满不高兴,于是在工作中马马虎虎,有一次曹操想知道母猪的数量,于是曹冲想狠狠耍曹操一把.举个例子,假如有16 ...

  10. EF+linq的增删改查

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...