ZOJ 1610 Count the Colors (线段树区间更新)
题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出。
思路 :线段树区间更新一下,然后标记一下,最后从头输出。
//ZOJ 1610
#include <cstdio>
#include <cstring>
#include <iostream> using namespace std ; int p[*],lz[*] ,hashh[*],hash1[*]; //void pushup(int rt)
//{
// if(p[rt << 1] == p[rt << 1 | 1])
// p[rt] = p[rt << 1] ;
// else p[rt] = -1 ;
//}
void pushdown(int rt)
{
if(lz[rt] != -)
{
lz[rt << ] = lz[rt << | ] = lz[rt] ;
p[rt << ] = p[rt << | ] = lz[rt] ;
lz[rt] = - ;
}
}
//void build(int l,int r,int rt)
//{
// lz[rt] = -1 ;
// if(l == r)
// {
// p[rt] = -1 ;
// return ;
// }
// int mid = (l + r) >> 1 ;
// build(l,mid,rt << 1) ;
// build(mid+1,r,rt << 1 | 1) ;
// pushup(rt) ;
//}
void update(int L,int R,int l,int r,int rt,int sc)
{
if(l >= L && r <= R)
{
lz[rt] = sc ;
p[rt] = sc ;
return ;
}
pushdown(rt) ;
int mid = (l+r) >> ;
if(mid >= L)
update(L,R,l,mid,rt << ,sc) ;
if(mid < R)
update(L,R,mid+,r,rt << | ,sc) ;
// pushup(rt) ;
}
void query(int l,int r,int rt)
{
if(l == r)
{
hashh[l] = p[rt] ;
return ;
}
pushdown(rt) ;
int mid = (l+r) >> ;
query(l,mid,rt << ) ;
query(mid+,r,rt << | ) ;
}
void Init()
{
memset(lz,-,sizeof(lz)) ;
memset(hashh,,sizeof(hashh)) ;
memset(hash1,,sizeof(hash1)) ;
memset(p,-,sizeof(p)) ;
}
int main()
{
int n ,x1,x2,c;
while(cin >> n )
{
Init() ;
for(int i = ; i < n ; i++)
{
cin >> x1 >> x2 >> c ;
update(x1,x2-,,,,c) ;
}
query(,,) ;
for(int i = ; i <= ; i++)
{
if(hashh[i] != hashh[i-])
{
if(hashh[i-] != -)
hash1[hashh[i-]] ++ ;
}
}
if(hashh[] != -)
hash1[hashh[]]++ ;
for(int i = ; i <= ;i++)
{
if(hash1[i])
{
printf("%d %d\n",i,hash1[i]) ;
}
}
puts("") ;
}
return ;
}
ZOJ 1610 Count the Colors (线段树区间更新)的更多相关文章
- zoj 1610 Count the Colors 线段树区间更新/暴力
Count the Colors Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...
- ZOJ 1610 Count the Color(线段树区间更新)
描述Painting some colored segments on a line, some previously painted segments may be covered by some ...
- ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- ZOJ 1610 Count the Colors (线段树成段更新)
题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...
- 【POJ 2777】 Count Color(线段树区间更新与查询)
[POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4094 ...
- ZOJ 1610.Count the Colors-线段树(区间染色、区间更新、单点查询)-有点小坑(染色片段)
ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting s ...
- ZOJ 5638——Prime Query——————【线段树区间更新,区间查询,单点更新】
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a s ...
- poj 2777 Count Color(线段树 区间更新)
题目:http://poj.org/problem?id=2777 区间更新,比点更新多一点内容, 详见注释, 参考了一下别人的博客.... 参考博客:http://www.2cto.com/kf/ ...
- ZOJ1610 Count the Colors —— 线段树 区间染色
题目链接:https://vjudge.net/problem/ZOJ-1610 Painting some colored segments on a line, some previously p ...
随机推荐
- chattr 与 lsattr 命令详解
PS:有时候你发现用root权限都不能修改某个文件,大部分原因是曾经用chattr命令锁定该文件了.chattr命令的作用很大,其中一些功能是由Linux内核版本来支持的,不过现在生产绝大部分跑的li ...
- Android之通过向WebService服务器发送XML数据获取相关服务
原理图如下: 即客户端向WebService服务器通过HTTP协议发送XML数据(内部包含调用的一些方法和相关参数数据),然后WebService服务器给客户端返回一定的XML格式的数据 ...
- Go字符串函数
下面的代码中,列出了Go官方包中常见的字符串函数. package main import s "strings" import "fmt" //为打印函数起个 ...
- [转]linux时间同步
转自:http://www.jotop.com/2012/vpsinfo_0525/439.html 美国的vps大多都是国外的时间,让我们的程序总是不适应.那么如何调整linux的时间为北京时间?修 ...
- 8 C#中的字符串输出
我们在前面已经用Console.WriteLine("*********")往dos窗口中输出过字符串.我们还定义过字符串的变量. string words ="我喜欢D ...
- Android编程: Activity生命周期和LogCat使用
学习内容:Activity生命周期和LogCat使用 ====Activity生命周期==== 图示(转载): 创建 onCreate重启 onRestart开始 onStart恢复 ...
- My First Django Project - <Django + MySQL + Ajax> (1)
因为最近工作有些信息需要额外花时间去收集,但是现在有相关的operations每天记录状态,但是没有一个很好的状态收集工具,将状态收集起来,所以很多情况下我们不知道是状态变好了,还是变差.如果使用EX ...
- Oracle数据文件在open状态被删除的恢复记录
1.查看当前状态: SQL> select status from v$instance; STATUS------------OPEN SQL> show parameter name; ...
- cocos2dx 3.x中的渲染机制
1.由2.x的渲染节点,变成添加渲染命令,可以避免重复渲染相同的节点,提高了渲染效率 2.单机游戏通常要求apk包在30M以内,没压缩1M会有1%的转换率(下载转换率),即收入会提高 3.2.x中首先 ...
- 在Eclipse中制作SSH配置文件提示插件
原文地址:http://blog.csdn.net/longyuhome/article/details/8968093 这篇博客算是对原先的“在Eclipse中制作和使用struts2配置文件提示插 ...