题目链接

题意 : 一根木棍,长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 (线段树区间更新)的更多相关文章

  1. zoj 1610 Count the Colors 线段树区间更新/暴力

    Count the Colors Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...

  2. ZOJ 1610 Count the Color(线段树区间更新)

    描述Painting some colored segments on a line, some previously painted segments may be covered by some ...

  3. ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

  4. ZOJ 1610 Count the Colors (线段树成段更新)

    题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...

  5. 【POJ 2777】 Count Color(线段树区间更新与查询)

    [POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4094 ...

  6. ZOJ 1610.Count the Colors-线段树(区间染色、区间更新、单点查询)-有点小坑(染色片段)

    ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting s ...

  7. ZOJ 5638——Prime Query——————【线段树区间更新,区间查询,单点更新】

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  8. poj 2777 Count Color(线段树 区间更新)

    题目:http://poj.org/problem?id=2777 区间更新,比点更新多一点内容, 详见注释,  参考了一下别人的博客.... 参考博客:http://www.2cto.com/kf/ ...

  9. ZOJ1610 Count the Colors —— 线段树 区间染色

    题目链接:https://vjudge.net/problem/ZOJ-1610 Painting some colored segments on a line, some previously p ...

随机推荐

  1. [原创]pg_shard使用场景及功能测试

    pg_shard是一个PostgreSQL的sharding extension.可以用于Shards.Replicates tables和高可用.它可以在不修改Applications的情况下无缝分 ...

  2. 向plsql中导入数据

    1.TOOLS-->ODBC IMPORTER 2.TOOLS-->TEXT IMPORTER3.sqlldr userid=zj/zj@orcl control=D:\test.ctl ...

  3. hdu 5326 Work

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5326 Work Description It’s an interesting experience ...

  4. hdu 5154 Harry and Magical Computer

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5154 Harry and Magical Computer Description In reward ...

  5. Python3.x List方法集合

    Python中的一个内置的基础类型叫List,类比于OC中的Array..他是有序的,那么下面写一些基础的方法,以备需要时候查阅: 1>获取List的长度 len(List) 2> 索引访 ...

  6. Python实现nb(朴素贝叶斯)

    Python实现nb(朴素贝叶斯) 运行环境 Pyhton3 numpy科学计算模块 计算过程 st=>start: 开始 op1=>operation: 读入数据 op2=>ope ...

  7. 如何给ActiveX控件添加“事件”“属性”“标准事件”“自定义事件”等一些相关操作

    上一篇小编带大家熟悉了一下ActiveX的建立以及相关的概念,(http://blog.csdn.net/u014028070/article/details/38424611) 本文介绍下如何给控件 ...

  8. Ajaxadr ajax跨域请求crossdomain

    最近工作需要用到ajax跨域请求参数,网上找很很久,最终得到解决之道.分享一下吧,希望能帮到各位 也许你已经发现在浏览器直接敲路径能获得对方提供接口的参数,而一到项目中Ajax请求却老是失败.原因是, ...

  9. To add private variable to this Javascript literal object

    You can use number as function/variable name, the numberic name can't be accessed from parent scope, ...

  10. Daily Scrum6

    今天我们小组开会内容分为以下部分: part 1: Anti-spam and anti-abuse module模块总结: part 2: 部分优化代码的展示于交流: part 3:针对用户积分模块 ...