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. FFMPEG: avformat_find_stream_info()函数

    av_find_stream_info()中是要不断的读取数据包,解码获得相应的信息 其中: st->codec->codec_type:0:视频,1:音频,2:数据 st->cod ...

  2. x264中重要结构体参数解释,参数设置,函数说明 <转>

    x264中重要结构体参数解释http://www.usr.cc/thread-51995-1-3.htmlx264参数设置http://www.usr.cc/thread-51996-1-3.html ...

  3. C# WinForm 关闭登陆窗体后进程还再内存怎么办?

    问题:我们通常再制作WinForm应用程序的时候,运行程序的第一个窗口一般是登陆窗口.代码如下: 那么这种方式有一个弊端,这种启动方式,其实就是把登陆窗口设置为主窗体.因此,再登陆后,我们通常是调用H ...

  4. Developer tools

    20. Developer tools Spring Boot includes an additional set of tools that can make the application de ...

  5. C++下基本类型所占位数和取值范围

    原文:http://hi.baidu.com/magicdemon/blog/item/821b2e22d7df494cad34debd.html C++下基本类型所占位数和取值范围: 符号属性    ...

  6. 框架之 hibernate简单入门

    hibernate框架的搭建 Hibernate框架的概述 1. Hibernate框架的概述 * Hibernate称为 * Hibernate是一个开放源代码的对象关系映射(ORM)框架,它对JD ...

  7. TaikrSpaceShooterStartKit.unitypackage包下载地址

    有好多教程里面没有资源包,现在加密分享给大家 unity4.*  链接: https://pan.baidu.com/s/1XMo2zVpV3ZhkNZKOb6H0yw 密码: tqnt unity5 ...

  8. Blender 工具使用——显示键盘和鼠标操作

    Blender 工具使用--显示键盘和鼠标操作 Blender自己本身就带有显示按键和鼠标的功能,就是3D View: Screencast Keys插件. 打开 File(文件) -> Use ...

  9. Entity Framework Tutorial Basics(16):Linq-to-Entities Projection Queries

    Linq-to-Entities Projection Queries: Here, you will learn how to write LINQ-to-Entities queries and ...

  10. Sql Server 2008 Management studio安装教程

    Sql Server 2008 Management studio安装教程     以下介绍Visual Studio 2010已安装后,sql server 2008 management stud ...