#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
const int MAXN=;
struct Node
{
int l,r;
int color;
}tr[MAXN*];
int color[MAXN];
int temp;
void build(int i,int l,int r)
{
tr[i].l=l;
tr[i].r=r;
//-1表示没有颜色
tr[i].color=-;
if(l+==r)
return;
int mid=((l+r)>>);
build(i<<,l,mid);
build((i<<)|,mid,r);
}
void insert(int i,int l,int r,int c)
{
if(l==r)
return;
if(tr[i].color==c)
return;
if(l<=tr[i].l&&r>=tr[i].r)
{
tr[i].color=c;
return;
}
//存在颜色,往下更新
if(tr[i].color>=)
{
tr[i<<].color=tr[i].color;
tr[(i<<)|].color=tr[i].color;
//表示有多种颜色
tr[i].color=-;
}
int mid=((tr[i].l+tr[i].r)>>);
if(r<=mid)
insert(i<<,l,r,c);
else if(l>=mid)
insert((i<<)|,l,r,c);
else
{
insert(i<<,l,mid,c);
insert((i<<)|,mid,r,c);
}
tr[i].color=-;
}
//统计各颜色的段数
void query(int i)
{
if(tr[i].color==-)
{
temp=-;
return;
}
if(tr[i].color!=-)
{
//temp存的是前一段的颜色
if(tr[i].color!=temp)
{
color[tr[i].color]++;
temp=tr[i].color;
}
return;
}
if(tr[i].l+!=tr[i].r)
{
query(i<<);
query((i<<)|);
}
}
int main()
{
int n,a,b,c;
int Max;
while(scanf("%d",&n)!=EOF)
{
build(,,);
Max=;
while(n--)
{
scanf("%d%d%d",&a,&b,&c);
insert(,a,b,c);
if(c>Max)
Max=c;
}
temp=-;
memset(color,,sizeof(color));
query();
for(int i=;i<=Max;i++)
if(color[i])
printf("%d %d\n",i,color[i]);
printf("\n");
}
return ;
}

Count the Colors ZOJ - 1610 区间颜色覆盖的更多相关文章

  1. F - Count the Colors - zoj 1610(区间覆盖)

    有一块很长的画布,现在想在这块画布上画一些颜色,不过后面画的颜色会把前面画的颜色覆盖掉,现在想知道画完后这块画布的颜色分布,比如 1号颜色有几块,2号颜色有几块.... *************** ...

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

    链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/F http://acm.zju.edu.cn/onli ...

  3. F - Count the Colors ZOJ - 1610 线段树染色(染区间映射)

    题意:给一段0-8000的线段染色 问最后 颜色x 有几段 题解:标准线段树  但是没有push_up  最后查询是单点按顺序查询每一个点 考虑过使用区间来维护不同的线段有多少种各色的线段  思路是 ...

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

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

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

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

  6. 线段树专题—ZOJ1610 Count the Colors(涂区间,直接tag标记)

    Painting some colored segments on a line, some previously painted segments may be covered by some th ...

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

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

  8. 线段树区间染色 ZOJ 1610

    Count the Colors ZOJ - 1610 传送门 线段树区间染色求染色的片段数 #include <cstdio> #include <iostream> #in ...

  9. F - Count the Colors

    F - Count the Colors ZOJ - 1610   思路:调了一个小时,但是发现自己线段树木有写错,颜色统计出了错误.但是不明白自己颜色统计为什么错了. 求大佬指点迷津.思路很简单,就 ...

随机推荐

  1. 3.部署场景1:带有遗留的Open vSwitch

    部署场景1:带有遗留的Open vSwitch 此场景描述了使用带有Open vSwitch(OVS)的ML2插件的OpenStack网络服务的(基本)实现. 遗留的实现通过为普通用户提供一种方法来管 ...

  2. 2、TCP/IP

    TCP/IP协议栈:物理层.数据接口层.网络层.传输层.应用层或网络接口层.网络层.传输层.应用层 TCP/IP协议栈的核心协议:1.TCP2.UDP3.ICMP4.IGMP5.ARP:映射IP→Et ...

  3. 百度MP3音乐API接口及应用

    当你在百度去搜索一首歌时,你会发现有种更简单的方法. http://box.zhangmen.baidu.com/x?op=12&count=1&title=歌名$$作者$$$$ 例如 ...

  4. Mysql的基本查询语句

    聚集函数 mysql有5个聚集函数,分别是AVG,MAX,MIN,SUM,COUNT. 分组 分组的使用group by作为关键字,having作为条件关键字. having和where的区别:1.w ...

  5. phpstorm+xmapp post不能传值

    https://blog.csdn.net/apple_wheat/article/details/72937035 问题的原因在于: PhpStorm默认使用的是自带的内部服务器,却不使用XAMPP ...

  6. FastDFS 原理介绍

    1 功能简介         FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负载均衡的问题.特别适 ...

  7. STP 生成树协议 RSTP 快速生成树

    STP(Spanning Tree Protocol)是生成树协议的英文缩写 该协议可应用于在网络中建立树形拓扑,消除网络中的环路,并且可以通过一定的方法实现路径冗余,但不是一定可以实现路径冗余.生成 ...

  8. Ubuntu14.04安装及配置mysql5.7.19

    通过uname -a或lsb_release -a 查看版本信息 ,确定linux的发行版是debian还是ubuntu.root@suepc:/usr/local# uname -aLinux su ...

  9. Vue之Vuex的使用

    重点看懂这张图: 重点记住: 1.Mutation 必须是同步函数,即mutations里只能处理同步操作. 2.如果处理的是同步操作可直接commit提交mutations更改state,如果是异步 ...

  10. js 细节

    1.js中var a=s=1和var a=1,s=1的区别 function fl() { ; } function fl1() { , s = ; } 看出问题所在了吗? var q=w=1 中的s ...