线段树-区间延迟修改-zoj-1610

Count the Colors

Description

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

大意:为线段上的子线段涂不同颜色的色块,新涂的会覆盖掉旧的。对应于涂色过程的输入为每行三个整数 x1 x2 c ,代表线段中本次涂色的子线段的起点与终点。问到最后每种颜色各有多少块。

分析:将整个线段分割成单位长度为1的子线段。以数组color[i]表示(i,i+1)区间上的色块颜色(从0开始记)。每次涂色,都要修改一个区间,所以用线段树来维护区间信息。

 

时间: 2024-08-03 04:05:49

线段树-区间延迟修改-zoj-1610的相关文章

POJ 3468 线段树 区间更新区间查询

题意:给出一段数列,任意区间加上一个整数v,任意区间查询.给出N个数,Q次操作. 线段树的题,延迟指针不更新到底就行了. #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define maxn 100005 long long sum[maxn<<2],col[maxn<<2]; void

高级数据结构中,线段树问题

问题描述 高级数据结构中,线段树问题 高级数据结构中,线段树可以处理很多区间问题,但是这些数据结构在现实项目中用 得多吗?还是这只是存在于竞赛中而已.如果现实项目中有用到,能不能举个例子? 解决方案 我曾级听过一个大牛说,线段树用得很少,基本没有用到... 解决方案二: 高级数据结构 - 线段树(1)数据结构--线段树--区间涂色问题高级数据结构 - 线段树(2)

《程序设计解题策略》——1.3 利用线段树解决区间计算问题

1.3 利用线段树解决区间计算问题 在现实生活中,我们经常遇到与区间有关的问题,例如,记录一个区间的最值(最大或最小值)和总量,并在区间的插入.删除.修改中维护这些最值和总量:再如,统计若干矩形并的面积.线段树拥有良好的树形二分特征,我们可以从其定义和结构中发现,在线段树的基础上完成这些问题的计算操作,是十分简捷和高效的.1.3.1 线段树的基本概念 一棵二叉树,记为T(a,b),参数a.b表示该节点表示区间[a,b].区间的长度b-a记为L.递归定义T[a,b]: 若区间长度L>1:区间[a,

线段树-点修改-hdoj-1754

I Hate It   Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老师有时候需要更新某位同学的成绩. Input 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0<N<=200000,0<M<5000 ),分别代表学生的数目和操作的数目. 学生ID编

zoj 1610 Count the Colors

点击打开链接zoj 1610 思路:线段树成段更新 分析: 1 题目给定n个区间的更新,然后要我们输出在这写所有的区间内能够见到的颜色的次数,只有连续的才算一次 2 简单的线段树的成段更新,做n的update,最后在查询一下然后输出 代码: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int MAXN

POJ3468&amp;#160;线段树-模板题

Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. In

线段树(Segment Tree)

1.概述 线段树,也叫区间树,是一个完全二叉树,它在各个节点保存一条线段(即"子数组"),因而常用于解决数列维护问题,基本能保证每个操作的复杂度为O(lgN). 线段树是一种二叉搜索树,与区间树相似,它将一个区间划分成一些单元区间,每个单元区间对应线段树中的一个叶结点. 对于线段树中的每一个非叶子节点[a,b],它的左儿子表示的区间为[a,(a+b)/2],右儿子表示的区间为[(a+b)/2+1,b].因此线段树是平衡二叉树,最后的子节点数目为N,即整个线段区间的长度. 使用线段树可以

c++-帮我看一下这段线段树的代码应该怎么用?有问题吗?

问题描述 帮我看一下这段线段树的代码应该怎么用?有问题吗? #include#define MAXN 10005struct node{ int left; int right; int mid; int cover;};node SegTree[3*MAXN];void BuildSegTree(int lint rint num){ SegTree[num].left=l; SegTree[num].right=r; SegTree[num].mid=(l+r)/2; if(l+1!=r)

[算法系列之二十三]线段树(Interval Tree)

一 背景 在信息学竞赛中,我们经常会碰到一些跟区间有关的问题,比如给一些区 间线段求并区间的长度,或者并区间的个数等等.这些问题的描述都非常简单,但是通常情况下数据范围会非常大,而朴素方法的时间复杂度过高,导致不能在规定时间内得到问题的解.这时,我们需要一种高效的数据结构来处理这样的问题,在本文中,我们介绍一种基于分治思想的数据结构--线段树. 二 简介 线段树是一种二叉树形结构,属于平衡树的一种.它将线段区间组织成树形的结构,并用每个节点来表示一条线段.一棵[1,10)的线段树的结构如图1.1