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.

<b< dd="">

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.

<b< dd="">

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

<b< dd="">

Sample Output

1 1
2 1
3 1

1 1

0 2
1 1

因为是线段树专题,就思考线段树,由于刚用线段树,这里的建树感觉没用,但是不确定,不过Pushup果断弃用。还有就是Query的时候是需要跑所有叶节点的,所以不需要那些判断, 大体思路正确,就是没想到用last记录。

 #include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define FO freopen("in.txt","r",stdin);
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout << "&&" << x << "&&" << endl;
#define lowbit(x) (x&-x)
#define mem(a,b) memset(a, b, sizeof(a));
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=;
const int inf = 0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head const int maxn=; //last 上一段的颜色
int lazy[maxn<<],n,ans[maxn],last;//lazy就是树,不需要处理什么信息 void Pushdown(int rt) {
if(lazy[rt]!=-) {
lazy[rt<<]=lazy[rt<<|]=lazy[rt];
lazy[rt]=-;
}
} void Updata(int rt,int L,int R,int l,int r,int val) {
if(L>=l&&R<=r) {
lazy[rt]=val;
return;
}
Pushdown(rt);
int mid=(L+R)>>;
if(l<=mid) Updata(rt<<,L,mid,l,r,val);
if(r>mid) Updata(rt<<|,mid+,R,l,r,val);
} void Query(int rt,int L,int R,int l,int r) {//不要太死板,学会变通
if(L==R) {
if(lazy[rt]!=-&&lazy[rt]!=last) {//巧妙
ans[lazy[rt]]++;
}
last=lazy[rt];
return;
}
Pushdown(rt);
int mid=(L+R)>>;//需要遍历所有叶节点
Query(rt<<,L,mid,l,r);
Query(rt<<|,mid+,R,l,r);
} int main() {
while(~scanf("%d",&n)) {
mem(ans,);
mem(lazy,-);
int x,y,val;
while(n--) {
scanf("%d%d%d",&x,&y,&val);
Updata(,,maxn,x+,y,val);//把0 变为 1
}
last=-;
Query(,,maxn,,maxn);
rep(i,,maxn) {
if(ans[i]) printf("%d %d\n",i,ans[i]);
}
printf("\n");
}
}

kuangbin专题七 ZOJ1610 Count the Colors (灵活线段树)的更多相关文章

  1. ZOJ-1610 Count the Colors(线段树染色,求染色段)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 https://vjudge.net/contest/318019# ...

  2. kuangbin专题七 HDU1166 敌兵布阵 (线段树或树状数组)

    C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况.由于 ...

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

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

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

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

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

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

  6. F - Count the Colors(线段树)

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

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

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

  8. Zoj 1610 Count the Colors (线段树+区间更新+暴力计数)

    题目大意: 有n次操作,每次都是对一根线中的一段区间进行染色(颜色并不相同),有时候后面的颜色有可能覆盖前面的颜色,问最后涂完色,能看到的颜色有几种,每种颜色有几部分? 解题思路: 这个题目建树的时候 ...

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

    https://cn.vjudge.net/problem/ZOJ-1610 题意 给一个n,代表n次操作,接下来每次操作表示把[l,r]区间的线段涂成k的颜色其中,l,r,k的范围都是0到8000. ...

随机推荐

  1. typescript相关知识点总结

    本文讲解typescript语法 由于js语法本身的混乱,再加上目前框架的割据,导致typescript用起来没有一致性,本文尽量总结实际开发中可能会用到的知识点 目录 数据类型 类型断言 duck ...

  2. Drools学习笔记2—Conditions / LHS 匹配模式&条件元素

    Rule的LHS由条件元素(Conditional Elements—CE)和匹配模式(Patterns)组成 Patterns被用来指示出fact的字段约束 每个约束必须为true才能让RHS的ac ...

  3. Canopy聚类算法(经典,看图就明白)

    只有这个算法思想比较对,其他 的都没有一开始的remove: 原网址:http://www.shahuwang.com/?p=1021 Canopy Clustering 这个算法是2000年提出来的 ...

  4. python正则以及collections模块

    正则 一.认识模块  什么是模块:一个模块就是一个包含了python定义和声明的文件,文件名就是加上.py的后缀,但其实import加载的模块分为四个通用类别 : 1.使用python编写的代码(.p ...

  5. xcode 编译报错“Cannot create __weak reference in file using manual reference counting”解决办法<转>

    http://blog.csdn.net/ouq68/article/details/51003876 解决方法: Please set ‘Weak References in Manual Reta ...

  6. python爬虫(2)--Urllib库的高级用法

    1.设置Headers 有些网站不会同意程序直接用上面的方式进行访问,如果识别有问题,那么站点根本不会响应,所以为了完全模拟浏览器的工作,我们需要设置一些Headers 的属性. 拆分这些请求,我们只 ...

  7. Spring 已看 没用

    注解 @Autwired 依赖注入  作用: 自动按照类型注入.当使用注解注入属性时,set方法可以省略.它只能注入其他bean类型.当有多个类型匹配时,使用要注入的对象变量名称作为bean的id,在 ...

  8. Libcurl 简明使用指南

    http://blog.csdn.net/weiling_shen/article/details/7620397 我们的程序中使用的是人家的Easy.h头文件.....完成文件的上传和下传. 尤其是 ...

  9. C++ 中 const 使用

    如果你一看见C++中const就脱口而出:“常量!”那只能说明你对c++不甚了解.或者说你太2了. const得一些使用方法与场景如下: 1:const修饰普通变量,全局变量,静态变量 ; ; 变量保 ...

  10. Mat_类

    Mat_类是对 Mat 类的一个包装,其定义如下: template<typename _Tp> class Mat_ : public Mat { public:     //只定义了几 ...