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 ...
随机推荐
- [Environment Build] Win10下Appach配置
1. Apache下载,登录http://httpd.apache.org/download.cgi,选择Files for Microsoft Windows, 有以下几个选择, 我选择的是Apac ...
- mac os x 系统安装 genymotion android 模拟器
如果你有 apk 文件 想 运行一下看看 ,但是又没有 android 设备 ,那么 genymotion 将会是一个 很好的解决方案. 1.安装 下载链接: https://cloud.geny ...
- gcc 创建库及使用
gcc -shared hello.c -o libhello.so gcc -o test test.c -L库所在目录 -l库名
- linux - 自动删除n天前日志
1.删除文件命令: find 对应目录 -mtime +天数 -name "文件名" -exec rm -rf {} \; 实例命令: find /opt/soft/log/ -m ...
- 团队开发-极速蜗牛-NABC模型
特点:益智,操作简单. N(need):手机小游戏,可以让大家打发无聊的时间,比如:排队打饭,课间休息,等公交等地铁,拿出手机玩玩小游戏. A(approach):基于光的反射原理,编写的小游戏. B ...
- gitlab&fengoffice的ldap配置
1.fengoffice配置config/ldap_config.php $config_ldap = array ( 'binddn' => 'cn=admin,dc=xxx,dc=xxx', ...
- IOS常用加密Encryption
NSString+Encryption.h // // NSString+Encryption.h // haochang // // Created by Administrator on 14-4 ...
- 在线自动下载最新版本jquery
<script src="http://code.jquery.com/jquery-latest.js">
- Java Applet使用
问题描述: Java Applet使用 参考资料: http://docs.oracle.com/javase/tutorial/deployment/applet/depl ...
- bzoj 1497 最小割模型
我们可以对于消费和盈利的点建立二分图,开始答案为所有的盈利和, 那么源向消费的点连边,流量为消费值,盈利向汇连边,流量为盈利值 中间盈利对应的消费连边,流量为INF,那么我们求这张图的最小割,用 开始 ...