zoj1610 线段树
//Accepted 804 KB 40 ms
//整个题,都是坑
//1.The first line of each data set contains exactly one integer n,
//1 <= n <= 8000, equal to the number of colored segments
//意思是:n表示染色线段的条数,而不是区间的总长度
//2.x1 and x2 indicate the left endpoint and right endpoint of the segment, c indicates the color of the segment.
//x1 ,x2 表示染色区间的端点位置,而染色的是区间
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
/**
* This is a documentation comment block
* 如果有一天你坚持不下去了,就想想你为什么走到这儿!
* @authr songt
*/
;
int color[imax_n];
struct node
{
int l,r;
int c;
int change;
}f[imax_n*];
void build(int t,int l,int r)
{
f[t].l=l;
f[t].r=r;
f[t].c=;
f[t].change=;
if (l==r)
{
return ;
}
;
build(*t,l,mid);
build(*t+,mid+,r);
}
void update(int t,int l,int r,int c)
{
if (f[t].l==l && f[t].r==r)
{
f[t].c=c;
f[t].change=;
return ;
}
)
{
f[*t].c=f[t].c;
f[*t+].c=f[t].c;
f[*t].change=f[*t+].change=;
f[t].change=;
}
;
*t,l,r,c);
else
{
*t+,l,r,c);
else
{
update(*t,l,mid,c);
update(*t+,mid+,r,c);
}
}
}
int query(int t,int k)
{
;
if (f[t].l==f[t].r && f[t].l==k)
{
return f[t].c;
}
)
{
return f[t].c;
}
;
*t,k);
*t+,k);
}
int n;
int x,y,c;
void slove()
{
build(,,);
;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&c);
x++;
c++;
if (x>y) continue ;
update(,x,y,c);
}
int t1,t2;
t1=;
memset(color,,sizeof(color));
;i<=;i++)
{
t2=query(,i);
)
{
t1=t2;
continue ;
}
if (t2==t1) continue;
color[t2]++;
t1=t2;
}
;i<=;i++)
)
{
printf(,color[i]);
}
}
int main()
{
while (scanf("%d",&n)!=EOF)
{
slove();
printf("\n");
}
;
}
zoj1610 线段树的更多相关文章
- zoj-1610线段树刷题
title: zoj-1610线段树刷题 date: 2018-10-16 16:49:47 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道简单的线段树区间染色问 ...
- ZOJ-1610 线段树+两种查询方法(弥补我线段树区间填充的短板)
ZOJ-1610 线段树+两种查询方法(弥补我线段树区间填充的短板) 题意 题意:给一个n,代表n次操作,接下来每次操作表示把[l,r]区间的线段涂成k的颜色其中,l,r,k的范围都是0到8000 这 ...
- zoj1610线段树区间覆盖
链接https://vjudge.net/contest/66989#problem/F 坑爹的线段树,一直用区间更新做,做了半天一点眉目都没有,只好搜题解,感觉好堕落,经常不会做就搜题解,以后一定要 ...
- [ZOJ1610]Count the Colors(线段树,区间染色,单点查询)
题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=1610 题意:给一个长8000的绳子,向上染色.一共有n段被染色,问染 ...
- zoj1610(线段树)
题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 题意:在0-8000长的线段里面,按先后次序依次覆盖颜色, ...
- kuangbin专题七 ZOJ1610 Count the Colors (灵活线段树)
Painting some colored segments on a line, some previously painted segments may be covered by some th ...
- 线段树专题—ZOJ1610 Count the Colors
题意:给一个n,代表n次操作,接下来每次操作表示把[l.r]区间的线段涂成k的颜色当中,l,r,k的范围都是0到8000 分析:事实上就是拿线段树维护一段区间的颜色,整体用到的是线段树的区间更新把,可 ...
- 【ACM/ICPC2013】线段树题目集合(一)
前言:前一段时间在网上找了一个线段树题目列表,我顺着做了一些,今天我把做过的整理一下.感觉自己对线段树了解的还不是很深,自己的算法能力还要加强.光练代码能力还是不够的,要多思考.向队友学习,向大牛学习 ...
- bzoj3932--可持久化线段树
题目大意: 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si秒开始,在第 ...
随机推荐
- 机器学习与R语言
此书网上有英文电子版:Machine Learning with R - Second Edition [eBook].pdf(附带源码) 评价本书:入门级的好书,介绍了多种机器学习方法,全部用R相关 ...
- An unknown server-side error occurred while processing the command.处理
在调用resetAPP()时,报错:An unknown server-side error occurred while processing the command. 怎么解决呢?请看: 额,Ap ...
- UIButton 一个控件 实现 左图标右文本的效果
UIButton 一个控件 实现 左图标右文本的效果 如图,我们要实现一个 左边图标右边文本的效果,一般 可以考虑是 UIImageView + UILabel 不过,其实一个UIButton就可以搞 ...
- MySQL高可用性分析
版权声明:本文由易固武原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/203 来源:腾云阁 https://www.qclo ...
- servlet的配置和上下文
一.Servlet配置对象(ServletConfig):Servlet初始化时,容器调用其init(ServletConfig)方法,传递该对象. 1.获得对象方法: (1).直接使用getServ ...
- 安装SQL Server 2014
一:下载SQL SERVER 2014 https://www.microsoft.com/zh-cn/server-cloud/products/sql-server-editions/sql-se ...
- Uva-------(11462) Age Sort(计数排序)
B Age Sort Input: Standard Input Output: Standard Output You are given the ages (in years) of all ...
- 选择列表中的列无效,因为该列没有包含在聚合函数或 GROUP BY 子句中
选择列表中的列无效,因为该列没有包含在聚合函数或 GROUP BY 子句中 T-SQL核心语句形式: SELECT --指定要选择的列或行及其限定 [INTO ] --INTO子句 ...
- CI(CodeIgniter)框架介绍
CodeIgniter 是一个为用 PHP 编写网络应用程序的人员提供的工具包.它的目标是实现让你比从零开始编写代码更快速地开发项目,为此,CI 提供了一套丰富的类库来满足通常的任务需求,并且提供了一 ...
- SQL Server数据库(作业)
create datebase zuoye2gouse zuoyegocreate table student --学生表( Sno varchar(20) not null primary key, ...