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 线段树 题意 有一个长木板,现在往上面在一定区间内刷颜色,后来刷的颜色会掩盖掉前面刷的颜色,问每次一定区间内可以看到多少种颜色. 解题思路 这里使用线段树,因为 ...
随机推荐
- 手机端rem无限适配
参考文档: http://blog.csdn.net/xwqqq/article/details/54862279 https://github.com/amfe/lib-flexible/tree/ ...
- 分享一下我的个人微信小程序
分享一下我的个人微信小程序 1.有我平时整理的一些小程序相关的技术,供大家参考. 2.有几个好玩的例子 有问题可以一起参考
- SOC中的DMIPS_GFLOPS_GMACS的含义
l DMIPS全称叫Dhrystone MIPS 这项测试是用来计算同一秒内系统的处理能力,它的单位以百万来计算,也就是(MIPS) 上面的意思也就是,这个处理器测整数计算能力为(200*100万) ...
- [03]Go设计模式:工厂模式(Factory Pattern)
目录 工厂模式 一.简介 二.代码 三.参考资料 工厂模式 一.简介 工厂模式(Factory Pattern)是软件设计中最常用的设计模式之一.这种类型的设计模式属于创建型模式,它提供了一种创建对象 ...
- npm包的语义版本控制(Semantic Versioning of Packages)
本文删改自Node.js 8 the Right Way Part I Chapter 3 npm 使用语义版本控制(SemVer)来寻找包的最佳可用兼容版本. 以安装测试框架mocha为例 $ ...
- [转帖]SpringBoot集成redisson分布式锁
SpringBoot集成redisson分布式锁 https://www.cnblogs.com/yangzhilong/p/7605807.html 前几天同事刚让增加上这一块东西. 百度查一下 啥 ...
- SpringAOP异常:org.springframework.aop.aspectj.AspectJExpressionPointcut cannot be cast to com.....
Exception in thread "main" java.lang.ClassCastException: org.springframework.aop.aspectj.A ...
- Appium移动端测试--搭建测试环境
目录 文章目录如下 安装Android Studio及Android SDK 更改VDM默认存储路径 通过npm安装Appium Server 启动Appium GUI模式 Appium连接会话 Ap ...
- 《学渣的电子技术自学笔记》——三极管的放大区、截止区与饱和区(基于NPN型)
<学渣的电子技术自学笔记>--三极管的放大区.截止区与饱和区(基于NPN型) 1.放大区 三极管输出特性曲线近似水平的部分是放大区.在放大区,\(I_C=\overline{β}I_B ...
- 【Linux】一步一步学Linux——Linux系统常用快捷键(12) 待更新...
目录 00. 目录 01. Gnome下的快捷键 02. 其它 03. 参考 00. 目录 @ 参考博客:https://blog.csdn.net/dengjin20104042056/articl ...