Count the Colors ZOJ - 1610 区间颜色覆盖
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
const int MAXN=;
struct Node
{
int l,r;
int color;
}tr[MAXN*];
int color[MAXN];
int temp;
void build(int i,int l,int r)
{
tr[i].l=l;
tr[i].r=r;
//-1表示没有颜色
tr[i].color=-;
if(l+==r)
return;
int mid=((l+r)>>);
build(i<<,l,mid);
build((i<<)|,mid,r);
}
void insert(int i,int l,int r,int c)
{
if(l==r)
return;
if(tr[i].color==c)
return;
if(l<=tr[i].l&&r>=tr[i].r)
{
tr[i].color=c;
return;
}
//存在颜色,往下更新
if(tr[i].color>=)
{
tr[i<<].color=tr[i].color;
tr[(i<<)|].color=tr[i].color;
//表示有多种颜色
tr[i].color=-;
}
int mid=((tr[i].l+tr[i].r)>>);
if(r<=mid)
insert(i<<,l,r,c);
else if(l>=mid)
insert((i<<)|,l,r,c);
else
{
insert(i<<,l,mid,c);
insert((i<<)|,mid,r,c);
}
tr[i].color=-;
}
//统计各颜色的段数
void query(int i)
{
if(tr[i].color==-)
{
temp=-;
return;
}
if(tr[i].color!=-)
{
//temp存的是前一段的颜色
if(tr[i].color!=temp)
{
color[tr[i].color]++;
temp=tr[i].color;
}
return;
}
if(tr[i].l+!=tr[i].r)
{
query(i<<);
query((i<<)|);
}
}
int main()
{
int n,a,b,c;
int Max;
while(scanf("%d",&n)!=EOF)
{
build(,,);
Max=;
while(n--)
{
scanf("%d%d%d",&a,&b,&c);
insert(,a,b,c);
if(c>Max)
Max=c;
}
temp=-;
memset(color,,sizeof(color));
query();
for(int i=;i<=Max;i++)
if(color[i])
printf("%d %d\n",i,color[i]);
printf("\n");
}
return ;
}
Count the Colors ZOJ - 1610 区间颜色覆盖的更多相关文章
- F - Count the Colors - zoj 1610(区间覆盖)
有一块很长的画布,现在想在这块画布上画一些颜色,不过后面画的颜色会把前面画的颜色覆盖掉,现在想知道画完后这块画布的颜色分布,比如 1号颜色有几块,2号颜色有几块.... *************** ...
- (线段树) Count the Colors --ZOJ --1610
链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/F http://acm.zju.edu.cn/onli ...
- F - Count the Colors ZOJ - 1610 线段树染色(染区间映射)
题意:给一段0-8000的线段染色 问最后 颜色x 有几段 题解:标准线段树 但是没有push_up 最后查询是单点按顺序查询每一个点 考虑过使用区间来维护不同的线段有多少种各色的线段 思路是 ...
- 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 线段树区间更新/暴力
Count the Colors Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...
- 线段树专题—ZOJ1610 Count the Colors(涂区间,直接tag标记)
Painting some colored segments on a line, some previously painted segments may be covered by some th ...
- ZOJ1610 Count the Colors —— 线段树 区间染色
题目链接:https://vjudge.net/problem/ZOJ-1610 Painting some colored segments on a line, some previously p ...
- 线段树区间染色 ZOJ 1610
Count the Colors ZOJ - 1610 传送门 线段树区间染色求染色的片段数 #include <cstdio> #include <iostream> #in ...
- F - Count the Colors
F - Count the Colors ZOJ - 1610 思路:调了一个小时,但是发现自己线段树木有写错,颜色统计出了错误.但是不明白自己颜色统计为什么错了. 求大佬指点迷津.思路很简单,就 ...
随机推荐
- 今天更新IDEA后,我依旧要永久激活(支持2019.3.3版本)
起因 今天一早用IDEA写代码,看到有下角有提示更新,有点强迫症的我,就手欠的又点了下更新,结果尼玛悲剧了,居然许可证过期,IDEA过期了,如下图所示: 就想用下新功能,就这样对我,就给两天的使用时间 ...
- Java集合XMind与注意事项
Java中集合使用时的几个注意事项: 1.ArrayList和HashMap都具有扩容 ArrayList初始化数组长度为10,扩容后的容量为原来的1.5倍. HashMap初始化的数组长度为16,扩 ...
- GORM CRUD指南
CRUD通常指数据库的增删改查操作,本文详细介绍了如何使用GORM实现创建.查询.更新和删除操作. CRUD CRUD通常指数据库的增删改查操作,本文详细介绍了如何使用GORM实现创建.查询.更新和删 ...
- HDU_5057_分块
http://acm.hdu.edu.cn/showproblem.php?pid=5057 分块,保存每个块中每位对应数字的和,复杂的是getmum,左右下标所在的块不能直接读取block数组,要重 ...
- Linux系统资料
Linux的心得: 1)Linux由众多微内核组成,其源代码完全开源: 2)Linux继承了Unix的特性,具有非常强大的网络功能,其支持所有的因特网协议,包括TCP/IPv4. TCP/IPv6和链 ...
- Go语言实现:【剑指offer】反转链表
该题目来源于牛客网<剑指offer>专题. 输入一个链表,反转链表后,输出新链表的表头. Go语言实现: 迭代: /** * Definition for singly-linked li ...
- 解析如何防止XSS跨站脚本攻击
2012-11-20 09:03 (分类:网络安全) 这些规则适用于所有不同类别的XSS跨站脚本攻击,可以通过在服务端执行适当的解码来定位映射的XSS以及存储的XSS,由于XSS也存在很多特殊情况,因 ...
- Nginx安装(yum源)
CentOS7 $ vi /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/c ...
- CentOS6.5安装指定的PHP版本(php5.5)(转)
查询是否安装有php #rpm -qa|grep php 删除之前安装的php版本 (yum install 安装) #rpm -e php-fpm-5.3.3-47.el6.x86_64 --nod ...
- 9种分布式ID生成之 美团(Leaf)实战
整理了一些Java方面的架构.面试资料(微服务.集群.分布式.中间件等),有需要的小伙伴可以关注公众号[程序员内点事],无套路自行领取 更多优选 一口气说出 9种 分布式ID生成方式,面试官有点懵了 ...