题目

参考博客地址

题意:

  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. 谷歌浏览器调试javascript方法

    谷歌浏览器调试javascript方法 1 ctrl + shift + f 全局文件搜索 然后加断点 也可以直接编辑js文件 保存后 就更新了 一般用在点击事件上 ps:如果加了断点 刷新浏览断点消 ...

  2. WordPress 设计学习

    "One can never be defeated until defeat has been accepted as a reality"----- Bruce Lee 官网免 ...

  3. LeetCode 563. 二叉树的坡度(Binary Tree Tilt) 38

    563. 二叉树的坡度 563. Binary Tree Tilt 题目描述 给定一个二叉树,计算整个树的坡度. 一个树的节点的坡度定义即为,该节点左子树的结点之和和右子树结点之和的差的绝对值.空结点 ...

  4. Prometheus入门到放弃(7)之redis_exporter部署

    redis监控,prometheus需要使用redis_exporter客户端. 这里我们采用docker方式部署,既可以部署在redis所在服务器,也可以部署在其他机器: docker镜像地址:ht ...

  5. SpringBoot配置文件敏感信息加密-jasypt

    使用过SpringBoot配置文件的朋友都知道,资源文件中的内容通常情况下是明文显示,安全性就比较低一些.打开application.properties或application.yml,比如mysq ...

  6. python-tkinter使用方法——转载(二)

    转载URL:https://www.cnblogs.com/yudanqu/p/9467803.html Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包 ...

  7. Word样式教程

    目录 写在前面 样式可以解决什么问题? 本文适合于 快速入门 一切皆样式 样式与格式的关系 如何修改样式 建立新的样式 样式的匹配和更新 根据样式更新所选段落 根据所选段落更新样式 小结 进一步了解 ...

  8. Python第六章 面向对象

    第六章 面向对象 1.面向对象初了解 ​ 面向对象的优点: ​ 1.对相似功能的函数,同一个业务下的函数进行归类,分类 ​ 2.类是一个公共的模板,对象就是从具体的模板中实例化出来的,得到对象就得到一 ...

  9. AS3事件类型

    Event事件类型: ACTIVATE       激活事件 DEACTIVATE 对象休眠事件 ADDED      可视对象添加事件 ADDED_TO_STAGE 可视对象添加到舞台事件 REMO ...

  10. vue3 template refs dom的引用、组件的引用、获取子组件的值

    介绍 通过 ref() 还可以引用页面上的元素或组件. DOM 的引用 <template> <div> <h3 ref="h3Ref">Tem ...