线段树专题—ZOJ1610 Count the Colors(涂区间,直接tag标记)
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
Sample Output
1 1
2 1
3 1
1 1
0 2
1 1
题意:就是在一段区间涂成一种颜色,然后最后问你,每种颜色涂成了多少种不同颜色。
题解:注意一下范围所有都是8000,所以和hdu1698差不了太多,也是区间标记,根
的优先值大于儿子的,这样就是这道题的解法,最后一次总的询问,将color 1-8000染好
颜色,然后就处理一下就好了。
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<climits>
using namespace std;
const int MAXN=;
bool a[MAXN]={};
int b[MAXN]={},n,num=,color[MAXN],tree[MAXN*]={},x,y,z;
void change(int l,int r,int p,int x,int y,int zhi)
{
if (l>r) return;
if (l==x&&r==y) tree[p]=zhi;
else
{
if (tree[p]!=-)
{
tree[p*]=tree[p*+]=tree[p];
tree[p]=-;
}
int mid=(l+r)>>;
if (y<=mid) change(l,mid,p*,x,y,zhi);
else if (x>=mid+) change(mid+,r,p*+,x,y,zhi);
else
{
change(l,mid,p*,x,mid,zhi);
change(mid+,r,p*+,mid+,y,zhi);
}
}
}
void query(int l,int r,int p){
if (l>r) return;
if (tree[p]!=-)
{
for (int i=l;i<=r;i++)
color[i]=tree[p];
}
else
{
if (l==r) return;
int mid=(l+r)>>;
query(l,mid,p*);
query(mid+,r,p*+);
}
}
int main()
{
while (~scanf("%d",&n))
{
num=;
for (int i=;i<MAXN*;i++)
tree[i]=-;
for (int i=;i<MAXN;i++)
a[i]=b[i]=,color[i]=MAXN-;
for (int i=;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&z);
if (x!=y) change(,,,x+,y,z);
}
query(,,);
for (int i=;i<=;i++)
if (color[i]!=color[i-]) a[color[i]]=,b[color[i]]++;
for (int i=;i<MAXN-;i++)
{
if (a[i]) cout<<i<<" "<<b[i]<<endl;
}
cout<<endl;
}
}
线段树专题—ZOJ1610 Count the Colors(涂区间,直接tag标记)的更多相关文章
- 线段树专题—ZOJ1610 Count the Colors
题意:给一个n,代表n次操作,接下来每次操作表示把[l.r]区间的线段涂成k的颜色当中,l,r,k的范围都是0到8000 分析:事实上就是拿线段树维护一段区间的颜色,整体用到的是线段树的区间更新把,可 ...
- kuangbin专题七 ZOJ1610 Count the Colors (灵活线段树)
Painting some colored segments on a line, some previously painted segments may be covered by some th ...
- zkw线段树专题
题目来自大神博客的线段树专题 http://www.notonlysuccess.com/index.php/segment-tree-complete/ hdu1166 敌兵布阵题意:O(-1)思路 ...
- vj线段树专题
vj线段树专题题解 单点更新模板 void build(int x,int l,int r){//sum[x]控制l-r区域 if(l==r){Sum[x]=num[l];return ;} int ...
- [ZOJ1610]Count the Colors(线段树,区间染色,单点查询)
题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=1610 题意:给一个长8000的绳子,向上染色.一共有n段被染色,问染 ...
- Kuangbin 带你飞-线段树专题 题解
HDU 1166 敌兵布阵 单调更新区间查询和 #include <map> #include <set> #include <list> #include < ...
- 2018 UESTC 线段树专题
A - 一棵简单的线段树 A[1...n]初始全为0. 1. 给两个数p 和 x(1≤p≤n),单点更新 A[p] <- x 2. 给两个数L和R (1≤L<R≤n), L到R区间里这几 ...
- [ZOJ1610]Count the Colors
Description 画一些颜色段在一行上,一些较早的颜色就会被后来的颜色覆盖了. 你的任务就是要数出你随后能看到的不同颜色的段的数目. Input 每组测试数据第一行只有一个整数n, 1 < ...
- 线段树专题 POJ3468 A Simple Problem with Integers
题意:n个点.m个操作.两种操作类型.C X Y K 表示区间[x,y]上每一个点值加k.Q X Y 求区间[x,y]的和 分析:线段树区间求和,裸模板 注意:结果会超int,要用long long ...
随机推荐
- 用PyCharm执行测试成功但无法生成HTMLTestRunner报告
问题:代码写的没问题,执行也成功了,但就是无法生成HTMLTestRunner的报告 其实这是编辑器搞得鬼,编辑器为了方便用户执行测试,都有一项功能,可以用编辑器来调用unittest或者nose来执 ...
- 常用Linux操作指令
-------------------------------Linux目录------------------------------- /:根目录,一般根目录下只存放目录,在Linux下有且只有一 ...
- Python 多线程库总结
多线程库总结 基于线程的并行性 threading模块 下面是一些基础函数,函数包括: 函数 threading.active_count() threading.current_thread() t ...
- LINUX下C语言编程调用函数、链接头文件以及库文件
LINUX下C语言编程经常需要链接其他函数,而其他函数一般都放在另外.c文件中,或者打包放在一个库文件里面,我需要在main函数中调用这些函数,主要有如下几种方法: 1.当需要调用函数的个数比较少时, ...
- Project 9:两种简单数列排序
1.冒泡法排序 /* 冒泡排序法的核心思想就是依次把最大的数换到最后面. 若有n个数 就需要通过n-1次循环来排序. 具体做法就是从第一个数开始 两个数比较大小大的换到后面,这样最大的就在最后了. 然 ...
- MPLS LDP随堂笔记2
前一天排错 Acl 1 匹配所有ospf的数据包 (目的 ospf建立邻居关系 传递路由条目) 2 放行UDP报文 让LDP邻居能互相收发HELLO包 4 放行TCP报文 让LDP邻居能够建立TCP会 ...
- HTTP请求响应机制与响应状态码
转载来源:http://blog.csdn.net/xyw591238/article/details/51907143 HTTP协议 Internate的基本协议是TCP/IP(传输控制协议和网际协 ...
- Mac Intellij Debug 模式
前言:本文的核心是记录debug的使用,与具体的操作系统无关. 1.什么是Debug Debug是程序的一种运行模式.用来发掘程序的走向,以及程序在运行过程中参数的变化. 2.Debug的作用 deb ...
- 转:深入Java集合学习系列:HashSet的实现原理
0.参考文献 深入Java集合学习系列:HashSet的实现原理 1.HashSet概述: HashSet实现Set接口,由哈希表(实际上是一个HashMap实例)支持.它不保证set 的迭代顺序:特 ...
- 团队作业7——Alpha冲刺之事后诸葛亮
Deadline: 2017-5-15 22:00PM,以博客发表日期为准 评分基准: 按时交 - 有分,检查的项目内容为事后诸葛亮分析报告 晚交 - 0分 迟交一周以上 - 倒扣本次作业分数 抄袭 ...