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. [转]Missing MSS Settings in Security Options of Group Policy (GPO)

    I'm currently working on a new Windows Server 2012 and Windows 8 project. As part of that project is ...

  2. Visual Studio 小工具

    折叠解决方案的每个项(Collapse Solution) 功能:折叠解决方案视图窗口中的解决方案或项目级别的每个项.包括嵌套在解决方案文件夹中的子项,引用和属性文件夹扩展节点. 源代码的文件头实现方 ...

  3. [Apache]如何查看apache服务器的error log(错误日志)

    在进行网页和服务器的测试时, 有时会提醒 500 Internal Server Error: The server encountered an internal error or misconfi ...

  4. Solaris10如何确认DirectIO是否已经启用

    对于Oracle而言,如果数据库存储在UFS文件系统上,启用DirectIO能够提高数据库性能.Oracle有个参数filesystemio_options可以控制数据库是否使用DirectIO.  ...

  5. flask 电影系统(2)

    标签,电影,上映预告数据模型设计 标签数据类型 id:编号 name:标题 movies:电影外键关联 addtime:创建时间 定义电影数据模型 id:编号 title:电影标题 url:电影地址 ...

  6. opencv中文网站相关下载

    http://wiki.opencv.org.cn/index.php/Download

  7. Python操作远程机器

    操作远程机器主要使用的有paramiko,WMI(Windows Management Instrumentation),SMBConnection. paramiko paramiko使用SSH2协 ...

  8. DHCP工作工程

    1.客户端请求IP 客户端发一个DHCP DISCOVEY(包含主机名.mac地址)广播包 2.服务端响应请求 DHCP服务器收到请求后,查看自己的地址池是否有合法的地址.如果有,广播一个DHCP o ...

  9. AngularJS分层开发

    为了AngularJS的代码利于维护和复用,利用MVC的模式将代码分离,提高程序的灵活性及可维护性. 1,前端基础层 var app=angular.module('appName',['pagina ...

  10. pageBean实现分页

    PageBean类 package com.xujingyang.domain ; import java.util.List ; /** * @author oldmonk * @date 2017 ...