题目

参考博客地址

题意:

  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 线段树的更多相关文章

  1. Count the Colors(线段树,找颜色段条数)

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

  2. [ZOJ1610]Count the Colors(线段树,区间染色,单点查询)

    题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=1610 题意:给一个长8000的绳子,向上染色.一共有n段被染色,问染 ...

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

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

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

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

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

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

  6. ZOJ-1610 Count the Colors ( 线段树 )

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Description Painting some co ...

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

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

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

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

  9. Count Color poj2777 线段树

    Count Color poj2777 线段树 题意 有一个长木板,现在往上面在一定区间内刷颜色,后来刷的颜色会掩盖掉前面刷的颜色,问每次一定区间内可以看到多少种颜色. 解题思路 这里使用线段树,因为 ...

随机推荐

  1. mybatis对实体的引用必须以 ';' 分隔符结尾

    今天在使用 generate 时(问题起源),由于扫描了mysql所有库下的user表,因此添加参数 nullCatalogMeansCurrent=true 添加改参数解决的原因 查看 但是添加后出 ...

  2. java开发异常Exception集锦

    背景:整理开发过程中的异常问题 java.lang.Exception: No tests found matching 一般出现在新导入的工程中.在sts中通过open project的方式导入工程 ...

  3. 16.Python略有小成(内置模块Ⅱ)

    Python(内置模块Ⅱ) 一.规范化开发 一个py文件中 文件加载问题 代码可读性,查询差 要将一个py文件分开,合理的分成多个py文件 配置文件放在一起 : 一些轻易不改变的变量,一般命名 set ...

  4. 33 Eclipse无法查看源码解决

    问题如图 点击 Attach Source 解决方法 下载src.zip包,src包地址:https://pan.baidu.com/s/1oAqqqHO 选择此src包即可

  5. 我在LeetCode的首次刷题

    到现在为止,我才发现我的博客一篇感受,心得,体会之言都没有. 今天就来随便扯扯. 刷题,是我最近一直在干的事情.也就每天写一两个.忘了就没写这种.也收藏了好几个刷题网站,当然第一次接触肯定是 WUST ...

  6. linux 下用C实现 ATM 自动取款机功能 (进程间通信)

    直接先上图: 项目需求: 主要分为两人大模块: 客户端 .进入时的功能开户.销户.登录.解锁 开户:输入姓名.身份证号.设置密码,如果开户成功,则服务器上保存一个账号信号(一个账号存一个文件,文件名建 ...

  7. Vue.js 2.x render 渲染函数 & JSX

    Vue.js 2.x render 渲染函数 & JSX Vue绝大多数情况下使用template创建 HTML.但是比如一些重复性比较高的场景,需要运用 JavaScript 的完全编程能力 ...

  8. JSVC安装

    执行./start-all.sh启动hadoop时报错 Starting datanodes node1: ERROR: Cannot set priority of datanode process ...

  9. SpringBoot指定额外需要扫描的包

    我们都知道,SpringBoot主启动类标注了@SpringBootApplication注解,该注解引入了@ComponentScan注解 所以默认的包扫描规则是,程序会自动扫描主启动类所在包及其子 ...

  10. Redis之RDB和AOF持久化介绍

    什么是数据库状态 redis是一个键值对的数据库服务器,服务器中通常包含中任意个非空的数据库,而每个数据库又可以包含任意个键值对,为了方便起见,我们将服务器中的非空数据库以及他们的键值对统称为数据库状 ...