Count the Colors 线段树
题意:
n范围[1,8000] , li 和 ri 的范围[0,8000]。 n个操作,每个操作是把 [li , ri]内的点修改成一个颜色c。 n个操作过后,按颜色从小到大 输出每种颜色分别有几块。
#include<iostream>
#include<cstdio>
#include <cctype>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
#define mem(a,x) memset(a,x,sizeof(a))
#define se second
#define fi first
const ll mod=1e9+;
const int INF= 0x3f3f3f3f;
const int N=1e5+; int add[N<<];
int flag; //flag判断相邻两个区间的颜色是否相同
int ans[N<<]; void push_down(int rt)
{
if(add[rt]>)
{
add[rt<<]= add[rt];
add[rt<<|]= add[rt];
add[rt]=-;
}
}
void Built(int l,int r,int rt)
{
add[rt]=;
if(l==r) return;
int m=l+r>>;
Built(l,m,rt<<);
Built(m+,r,rt<<|);
} void update(int x,int y,int c,int l,int r,int rt)
{
if(x<=l && r<=y)
{
add[rt]=c;
return;
}
push_down(rt);
int m=l+r>>;
if(x<=m) update(x,y,c,l,m,rt<<); //当寻找一个区间的时候,路径上的值全改成c
if(m<y) update(x,y,c,m+,r,rt<<|);//当寻找一个区间的时候,路径上的值全改成c
add[rt]=-; //寻找到了之后,把回头的路径全部改成-1,说明如果顺着这些点下来,一定能找到区间
} void query(int l,int r,int rt)
{
if(flag==add[rt]) return;
if(add[rt]==) //一次也没有被涂过
{
flag=; return;
}
if(add[rt]>)
{
if(flag!=add[rt]) //不是同一块海报
{
flag=add[rt];
ans[add[rt]]++;
}
return;
} //接下来是如果add[rt]== -1 ,表示顺着这个点 一定能找到区间
if(l==r)
return;
int m=l+r>>;
query(l,m,rt<<);
query(m+,r,rt<<|);
}
int main()
{
int x,y,z,n,m;
while(scanf("%d",&n)==)
{
mem(add,); //0表示该点没有涂色。
mem(ans,);
Built(,,); for(int i=;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&z);
update(x, y-, z+, ,,);
}
query(,,); for(int i=;i<=;i++)
{
if(ans[i]) printf("%d %d\n",i-,ans[i]);
}
cout<<endl;
}
}
Count the Colors 线段树的更多相关文章
- Count the Colors(线段树,找颜色段条数)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- [ZOJ1610]Count the Colors(线段树,区间染色,单点查询)
题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=1610 题意:给一个长8000的绳子,向上染色.一共有n段被染色,问染 ...
- 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 Colors (线段树成段更新)
题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...
- 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 ( 线段树 )
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Description Painting some co ...
- ZOJ1610 Count the Colors —— 线段树 区间染色
题目链接:https://vjudge.net/problem/ZOJ-1610 Painting some colored segments on a line, some previously p ...
- 【POJ 2777】 Count Color(线段树区间更新与查询)
[POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4094 ...
- Count Color poj2777 线段树
Count Color poj2777 线段树 题意 有一个长木板,现在往上面在一定区间内刷颜色,后来刷的颜色会掩盖掉前面刷的颜色,问每次一定区间内可以看到多少种颜色. 解题思路 这里使用线段树,因为 ...
随机推荐
- IntellJ idea maven打包——项目带有第三方jar包
今天用maven打包时,提示程序包com.aspose.slides不存在 原来第三方jar是直接导入的,打包时没找到 那项目中带有第三方jar包,怎么打包? 方法: 1.根路径建立lib包,将第三方 ...
- Consul服务告警之Watch机制
熔断保护在Consul和Ocelot中都有实现,意思就是当一个服务不正常时(比如我们的一个服务实例挂了,Consul的健康检查机制检测到了),应该给系统维护人员给以告警.在Consul中,服务告警也是 ...
- app内嵌h5页面在ios手机端滑动卡顿的解决方法
1.带滚动条的dom需加样式 -webkit-overflow-scrolling: touch;2.去掉 width:100%; height:100%
- Apache新的URL路由重写规则
在根目录下新建一个 .htaccess 后缀文件,将下面代码放进去即可 <IfModule mod_rewrite.c> Options +FollowSymlinks -Multivie ...
- python基础篇(五)
PYTHON基础篇(五) 算法初识 什么是算法 二分查找算法 ♣一:算法初识 A:什么是算法 根据人们长时间接触以来,发现计算机在计算某些一些简单的数据的时候会表现的比较笨拙,而这些数据的计算会消耗大 ...
- was8.5和aop的问题:JVMVRFY013 违反类装入约束
一.错误日志:Error 500: javax.servlet.ServletException: java.lang.VerifyError: JVMVRFY013 违反类装入约束 类=org/sp ...
- LeetCode 653. 两数之和 IV - 输入 BST(Two Sum IV - Input is a BST)
653. 两数之和 IV - 输入 BST 653. Two Sum IV - Input is a BST 题目描述 给定一个二叉搜索树和一个目标结果,如果 BST 中存在两个元素且它们的和等于给定 ...
- 【转帖】处理器的三国时代:DR公司盛气凌人,IBM转身成就微软
处理器的三国时代:DR公司盛气凌人,IBM转身成就微软 https://www.eefocus.com/mcu-dsp/360555 <处理器史话>之五 2016-04-06 15:24 ...
- 开发板与pc之间文件传输:kermit and lrzsz
imx6开发板与pc机之间通过串口传输文件步骤: 1. 安装好kermit并可以使用 2. 交叉编译lrzsz开源软件并把可执行程序lrz lsz拷贝到开发板 2.1 下载并解压lrzsz-0.12. ...
- centos7安装php7.3
安装php7.3 CentOS/RHEL 7.x: yum install epel-release yum install http://rpms.remirepo.net/enterprise/r ...