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 ...
随机推荐
- poj 2312 Battle City
题目连接 http://poj.org/problem?id=1840 Battle City Description Many of us had played the game "Bat ...
- umask设置导致的weblogic中的应用上传的文件没有权限打开
去年,在公司的某一weblogic上部署的web应用上传文件后却没有读的权限.因为weblogic在Linux上部署,上传文件是mount到了一台安装了NFS的Windows Server上. 当时本 ...
- centos6 自启动任务
tag: init upstart centos6.x 自启动 initctl event CentOS6开始转用Upstart代替以往的init.d/rcX.d的线性启动方式.upstart的概念就 ...
- iOS学习之C语言函数
一.函数的定义 返回值类型 函数名(参数类型 参数名, ...) { 功能语句; return 返回值; } 按照返回值和参数划分: 第一种: 无返回值 无参 void sayHello() { pr ...
- Easy-UI 动态添加DataGrid的Toolbar按钮
在前人的基础上进行的修改,不知道他是从哪里引用来的,所以没有粘贴引用地址. 原代码不支持1.3.6. 修改功能: 1.如果之前没有添加过工具,用这个方法不能添加(已修复): 2.估计是不支持1.3.6 ...
- Java Day 14
多线程--线程间通信 对同一个资源进行处理,但是任务却不同 线程间通信--等待唤醒机制 1.wait(); 线程处于冻结状态,被wait线程存储在线程池中 2.notify(); 从线程池唤醒一个 ...
- 字符串比较 忽略大小写 iphone
//不考虑大小写比较字符串1 NSString *astring01 = @"this is a String!"; NSString *astring02 = @"Th ...
- LeetCode-Data Stream as Disjoint Intervals
Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...
- 11.2Daily Scrum
人员 任务分配完成情况 明天任务分配 王皓南 做文件的网页和数据库连接,任务编号771 实现视频上传的功能 申开亮 实现视频浏览的功能,任务编号772 实现视频浏览的功能 王宇杰 后台测试,任务编号7 ...
- Mac下安装及配置Eclipse
1.安装Eclipse前先确认你的Mac上是否已安装java运行环境.进入终端,输入”java -version”,如果返回了java版本号则说明已安装,否则,请先安装java运行环境: 2.访问ec ...