题目

参考博客地址

题意:

  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. centos7.3部署memcached服务

    我们需要下载libevent和memcached这两个压缩包进行安装,可使用以下百度网盘链接进行下载 链接:https://pan.baidu.com/s/1vehZ5odzXFKwNjWT9_W0T ...

  2. [LeetCode] 482. License Key Formatting 注册码格式化

    You are given a license key represented as a string S which consists only alphanumeric character and ...

  3. 高级UI-画板Canvas

    Canvas可以用来绘制直线.点.几何图形.曲线.Bitmap.圆弧等等,做出很多很棒的效果,例如QQ的消息气泡就是使用Canvas画的 Canvas中常用的方法 初始化参数 Paint paint ...

  4. async + promise 解决回调地狱

    // 解决异步回调地狱的方案: async + promise async function writeFile() {   // 打开文件   const fd = await new Promis ...

  5. 如何配置STP

    一.搭建本次实验的拓扑结构 两台s5700交换机模拟核心交换,两台s3700交换机模拟接入交换机,核心上配置eth-trunk   二.开启所有交换机的stp功能 开启stp [S1]stp enab ...

  6. [HAOI2008]硬币购物-题解

    传送门 解答 根据容斥原理 \[ \left|\bigcap_{i=1}^n \overline{S_i}\right| = |U| - \left|\bigcup_{i=1}^n S_i\right ...

  7. 链表习题(6)-链表返回倒数第k个数的位置的值

    /*链表返回倒数第k个数的位置的值*/ /* 算法思想:先取得链表的长度len,之后获取len-k+1的位置元素的值 */ Elemtype Getelem_rear(LinkList L, int ...

  8. AVR单片机教程——按键状态

    好久没更新了,今天开始继续,争取日更. 今天我们来讲按键.开发板的右下角有4个按键,按下会有明显的“咔嗒”声.如何检测按键是否被按下呢?首先要把按键或直接或间接地连接到单片机上.与之前使用的4个LED ...

  9. STM32F030-UART1_DMA使用提示

    STM32F030-UART1_DMA使用提示 前言: 今天把STM32F030C8T6的串口DMA学习了一下,为了加快各位研发人员的开发进度,避免浪费大量的时间在硬件平台上,写出个人代码调试的经验. ...

  10. Testbench编写技巧

    一.基本架构(常用模板) `timescale 1ns/1ps //时间精度 `define Clock //时钟周期 module my_design_tb; //================= ...