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. 如何尽量避免引用jQuery

    Introduction 正如jQuery所宣称的一样,Write Less, Do More.很多时候我们喜欢用它来解决问题.但增加一个库必然意味着更大的网络负担,意味着更高的页面初始载入时间.并且 ...

  2. phpMyAdmin 缺少 mcrypt 扩展.请检查 PHP 配置.

    原文链接:http://zhidao.baidu.com/link?url=5Y4eT7bcnTHFUtzDMs7mvtsGc7jqbs2yqXG06AP5_6t7wukC7uVozSrbUf7iYl ...

  3. datagrid数据网格获取所有选中行的索引,插入某个列值为其他列的运算值

    获取所有选中行的索引,存入数组ary中: var data=$("#dg").datagrid("getSelections"); var ary=[]; fo ...

  4. android Random的使用

    一.Random 此类的实例用于生成伪随机数流.此类使用 48 位的种子,使用线性同余公式 (linear congruential form) 对其进行了修改. 如果用相同的种子创建两个 Rando ...

  5. 【Web应用-网络连接】关于 Azure Web 应用 4 分钟空闲连接的限制

    Azure Web 应用后台在处理耗时较长的请求时,并且在此期间,客户端和 Azure Web 应用没有数据交互,即 TCP 连接一直处于空闲状态,此种情况超过 4 分钟后,Azure Web 应用会 ...

  6. cocoapods学习

    1.安装 http://stackoverflow.com/questions/16459028/rvm-install-error-running-requirements-osx-port-ins ...

  7. hdu 6058 Kanade's sum (计算贡献,思维)

    题意: 给你一个全排列,要你求这个序列的所有区间的第k大的和 思路:比赛的时候一看就知道肯定是算贡献,也知道是枚举每个数,然后看他在多少个区间是第K大,然后计算他的贡献就可以了,但是没有找到如何在o( ...

  8. 虚拟DOM -------- 最易理解的解释

    虚拟DOM是最先由Facebook在react里使用的, 虚拟DOM是一个特别棒的概念,我们都知道,在浏览器上进行DOM操作的时候,会特别的消耗性能而且响应.渲染特别慢,但是有了虚拟DOM就不一样了, ...

  9. Jordan 标准型的推论

    将学习到什么 从 Jordan 标准型出发,能够获得非常有用的信息.   Jordan 矩阵的构造 Jordan 矩阵 \begin{align} J=\begin{bmatrix} J_{n_1}( ...

  10. CPP-基础:字节对齐

    一.   什么是字节对齐,为什么要对齐?      现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特定的 ...