#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. 如何优雅的将Mybatis日志中的Preparing与Parameters转换为可执行SQL

    原文链接 疫情期间大家宅在家里是不是已经快憋出“病”了~~ ​ 公司给开了VPN,手机电脑都能连,手机装上APP测试包,就能干活了,所以walking从2020.02.01入京以来,已经窝在家里11天 ...

  2. 全卷积网络FCN

    全卷积网络FCN fcn是深度学习用于图像分割的鼻祖.后续的很多网络结构都是在此基础上演进而来. 图像分割即像素级别的分类. 语义分割的基本框架: 前端fcn(以及在此基础上的segnet,decon ...

  3. selenium 操作下拉处理

    操作下拉框处理 在网页中,有时候会遇到下拉框处理,这时候使用Webdriver提供的select类来处理. ##操作下拉框处理 #coding = utf-8 from selenium import ...

  4. asp.net core 3.x 身份验证-3cookie身份验证原理

    概述 上两篇(asp.net core 3.x 身份验证-1涉及到的概念.asp.net core 3.x 身份验证-2启动阶段的配置)介绍了身份验证相关概念以及启动阶段的配置,本篇以cookie身份 ...

  5. HDU 3068 最长回文 (Manacher最长回文串)

    Problem Description 给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度.回文就是正反读都是一样的字符串,如aba, abba等   Input 输 ...

  6. Spring IOC容器源码分析

    注:本文转自https://javadoop.com/post/spring-ioc Spring 最重要的概念是 IOC 和 AOP,本篇文章其实就是要带领大家来分析下 Spring 的 IOC 容 ...

  7. Java并发编程(三):ReentrantLock

    ReentrantLock是可以用来代替synchronized的.ReentrantLock比synchronized更加灵活,功能上面更加丰富,性能方面自synchronized优化后两者性能没有 ...

  8. c++中的智能指针怎样释放连续的资源?

    以前学智能指针时有点想当然了,一直以为智能指针很智能,不管你让它管理的是单个资源还是连续的资源它都能正确的将资源释放,现在发现自己大错特错. 先看代码: #include <iostream&g ...

  9. ts的特殊数据类型

    四. Ts数据类型 tuple(元组类型):可以给数组指定位置存指定类型数据 例:let arr:[number, string] = [123, ‘123’]; enum(枚举):将数字转化为标识符 ...

  10. [jQuery]jQuery链式编程(六)

    链式编程 节约代码量 <button>快速</button> <button>快速</button> <button>快速</butt ...