Count the Colors ZOJ - 1610(线段树)

2.4G 12通道遥控器设计解析 本文深入分析基于NRF24L01+和STM32的2.4GHz 12通道无线遥控器原理图与系统架构,涵盖射频通信、多通道信号采集、协议转换(如S.Bus)、抗干扰设计及低延迟优化策略,适用于无人机与智能模型开发。 阅读详情

Count the Colors ZOJ - 1610

Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.

Your task is counting the segments of different colors you can see at last.

Input

The first line of each data set contains exactly one integer n, 1 <= n <= 8000, equal to the number of colored segments.

Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:

x1 x2 c

x1 and x2 indicate the left endpoint and right endpoint of the segment, c indicates the color of the segment.

All the numbers are in the range [0, 8000], and they are all integers.

Input may contain several data set, process to the end of file.

Output

Each line of the output should contain a color index that can be seen from the top, following the count of the segments of this color, they should be printed according to the color index.

If some color can't be seen, you shouldn't print it.

Print a blank line after every dataset.

Sample Input

5
0 4 4
0 3 1
3 4 2
0 2 2
0 2 3
4
0 1 1
3 4 1
1 3 2
1 3 1
6
0 1 0
1 2 1
2 3 1
1 2 0
2 3 0
1 2 1

Sample Output

1 1
2 1
3 1

1 1

0 2
1 1
题意:

给了每一线段的颜色,存在颜色覆盖,求表面上看能看到的颜色种类和各种颜色的段数

分析:

线段树维护区间颜色

code:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int MAXN = 8010;
struct Node{
    int l,r;
    int color;
}tre[MAXN*3];
int color[MAXN];
int temp;

void Build(int rt,int l,int r){
    tre[rt].l = l;
    tre[rt].r = r;
    tre[rt].color = -1;
    if(l + 1 == r) return;
    int mid = l + r >> 1;
    Build(rt<<1,l,mid);
    Build(rt<<1|1,mid,r);
}

void insert(int rt,int l,int r,int c){
    if(l == r) return;
    if(tre[rt].color == c) return;
    if(l <= tre[rt].l && r >= tre[rt].r){
        tre[rt].color = c;
        return;
    }
    if(tre[rt].color >= 0){
        tre[rt<<1].color = tre[rt].color;
        tre[rt<<1|1].color = tre[rt].color;
        tre[rt].color = -2;
    }
    int mid = tre[rt].l + tre[rt].r >> 1;
    if(r <= mid) insert(rt<<1,l,r,c);
    else if(l >= mid) insert(rt<<1|1,l,r,c);
    else{
        insert(rt<<1,l,mid,c);
        insert(rt<<1|1,mid,r,c);
    }
    tre[rt].color = -2;
}

void Count(int rt){
    if(tre[rt].color == -1){
        temp = -1;
        return;
    }
    if(tre[rt].color != -2){
        if(tre[rt].color != temp){
            color[tre[rt].color]++;
            temp = tre[rt].color;
        }
        return;
    }
    if(tre[rt].l + 1 != tre[rt].r){
        Count(rt<<1);
        Count(rt<<1|1);
    }
}
int main(){
    int n,a,b,c;
    int Max = 0;
    while(scanf("%d",&n) != EOF){
        Build(1,0,8000);
        Max = 0;
        while(n--){
            scanf("%d%d%d",&a,&b,&c);
            insert(1,a,b,c);
            if(c > Max) Max = c;
        }
        temp = -1;
        memset(color,0,sizeof(color));
        Count(1);
        for(int i = 0; i <= Max; i++){
            if(color[i]) printf("%d %d\n",i,color[i]);
        }
        printf("\n");
    }   
    return 0;
}
Shopee 虾皮API接口:商品详情采集的实践 随着电商行业的蓬勃发展,数据采集和分析在商业决策中扮演着越来越重要的角色。Shopee作为东南亚领先的电商平台,拥有大量的商品数据。通过Shopee的API接口,我们可以方便地获取商品详情,为数据分析和市场研究提供有力支持。本文将介绍如何使用Shopee API接口采集商品详情,并分享一些实践技巧。提供了丰富的数据接口,包括商品详情、店铺信息、订单数据等。通过API接口,开发者可以轻松地获取Shopee平台上的数据,进行进一步的处理和分析。Shopee API接口:商品详情采集的实践与技巧。 阅读详情

相关推荐

智能车竞赛卡丁快跑组:自动驾驶与人车交互技术实战解析

本文深入解析了智能车竞赛卡丁快跑组的技术核心,重点探讨了自动驾驶与人车交互两大模块的实战方案。文章详细拆解了从环境感知、路径规划到语音识别、命令执行的完整流程,并分享了基于单片机平台的调试心法与赛场经验,为参赛者提供了一套从零开始、分步攻坚的系统性备赛指南。

f0g1h2的博客 1177

zoj 1610 Count the Colors【暴力乱搞】

链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28619#problem/F Count the Colors Time Limit: 2 Seconds

free斩 1361

疾病负担研究(GBD)介绍

今天我们来聊一聊第一个公共数据库——GBD数据库,全称叫做global burden of disease(全球疾病负担),该数据库每年都会更新,目前已经更新到GBD2019。 这里直接给大家贴出网址:Global Burden of Disease Study 2019 (GBD 2019) Data Resources | GHDx 上图中红色圈圈标识的就是数据库的数据获取界面的链接,大家直接点击即可. 数据的检索十分方便: Context下拉菜单中可以选择不同的选项,默认是caus

weixin_44240228的博客 1万+

Segments POJ - 3304 判断直线与线段相交

题目链接:https://vjudge.net/problem/POJ-3304 转自:https://blog.youkuaiyun.com/sdsy191553/article/details/83067586 题意:给多条线段,问能否找到一条直线,将所有线段投影到上面后有至少一个公共交点。 思路:假设存在直线,对直线做垂线,当垂线在投影的公共区域时,它会经过所有线段。 问题变成了找这样的一条可以经过所有...

A 405

Proteus课设原理图及报告

1. I/O 口:32 个可编程 I/O 引脚,分成 4 个并行 I/O 端口 (P0, P1, P2, P3),P0 功能段选 a、b、c、d、e、f、g、dp 使其中部分点亮,P2 功能为位选 1、2、4.按键操作分析:P3.0-设置时钟的时间,P3.1-确定更改的时钟时间,P3.2-对。时钟设置标志 0 不设置,1 设置时,2 设置分,3 设置秒。P3.0 按下的次数对应 不设置,设置时,设置分,

2303_76688805的博客 1175

手把手教你用89C52单片机驱动0.96寸OLED(IIC接口,附完整代码)

本文详细介绍了如何使用89C52单片机通过I2C接口驱动0.96寸OLED显示屏,包括硬件连接、I2C通信原理、SSD1306驱动芯片的初始化及显存管理技巧,并提供了完整的代码示例和常见问题排查方法,帮助电子爱好者快速掌握OLED显示技术。

weixin_30781433的博客 369

音诺ai翻译机借助Vishay TSOP38238接收遥控信号

音诺AI翻译机通过集成Vishay TSOP38238红外接收模块,实现低功耗、高抗干扰的远程控制与多协议解码,支持通用遥控操作、语言切换及智能家居联动,提升无屏交互体验。

weixin_34620658的博客 1137

odoo19/18集成reportbro 打印插件 完美支持静默打印

ReportBro设计器 一个用于创建PDF和XLSX报告模板的javascript插件。ReportBro Designer可以轻松集成到您的Web应用程序中。每个人都可以设计和编辑文档模板,并直接在浏览器中预览它们。可以使用服务器上的 (有关完整的文档和演示,请参阅上的ReportBro项目网站。reportBro官方没有提供。测试环境:odoo17社区版。2.产品标签打印设计。

zxltwins的博客 2771

人机交互专题报告

人机交互专题报告   (2013-12-06 19:57:10) 转载▼   分类: 寻找牛股 人机交互专题报告 2013年9月7日 来源:齐鲁证券 http://blog.sina.com.cn/s/blog_a816de580101eoaj.html   投资要点  人机交互变革将是继个人计算

klzhang的专栏 2万+

AI 赋能测试全生命周期:多 Agent 协同的自动化提效方案

本文提出了一种基于Coze平台的多Agent协同测试解决方案,旨在解决软件测试中PRD解析不清晰、测试点覆盖不全、用例编写效率低、代码生成耗时等痛点。通过PRD优化、测试点生成、测试用例生成和单元测试框架生成四个Agent的协同工作,结合Cursor工具实现从需求到代码的全链路自动化。以电商平台登录模块为例,展示了从模糊PRD到标准化测试用例和可执行Java单元测试代码的完整转化流程。该方案通过AI赋能显著提升测试效率,减少人工干预,实现测试覆盖率≥95%,为快速迭代的软件研发提供了高效的测试自动化支持。

QINJIEEE的博客 1099

ldpc编解码器设计与仿真

计算校验节点到变量节点的消息 m_{c \to v}=2 \cdot atanh(\prod_{v’ \in N©\setminus v}tanh(\frac{m_{v’ \to c}}{2}))。计算变量节点到校验节点的消息 m_{v \to c}=L_{v,0}+\sum_{c’ \in M(v)\setminus c}m_{c’ \to v}。◦ 对于每个变量节点 v,计算最终 LLR 值 L_{v,f}=L_{v,0}+\sum_{c \in M(v)}m_{c \to v}。

youngerwang的博客 808

ZOJ 1610 Count the Colors(线段树经典)

Count the Colors Time Limit: 2000 msMemory Limit: 65536 KB Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones. Your task is counting the segments of different colors you can see at last.

深秋无痕 611

11、改进的加权轮询调度算法

本文详细介绍了对传统加权轮询(WRR)调度算法的改进方法,包括动态权重调整、优先级调度和预测机制,旨在提升系统的公平性、响应速度和适应性。通过设计与实现改进算法,并结合实验验证其在响应时间、资源利用率和公平性方面的显著提升,同时列举了该算法在数据中心、云服务平台、CDN及电商平台等实际场景中的应用案例。

day7的博客 189

线段树增强训练题 ZOJ1610 Count the Colors

线段树增强训练题 ZOJ1610 Count the Colors 线段树增强训练,啊啊啊,我还是太菜了 这道题调试起码4个小时,明明一道很简单的题目。。。。 题意也看了好久,与一开始还读错题意了,但是问题不大,在原来的代码上改改也可 题意:对一段长为8000的线段进行染色,颜色有8000种,每次对区间[l,r]进行染色,进行n次操作后,问你每一种颜色有几段。 很明显的区间修改和查询,不假思索就...

qq_33437973的博客 232

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

ZOJ - 1610 Count the Colors(模拟,线段树)

vjudge链接https://vjudge.csgrandeur.cn/problem/ZOJ-1610 ZOJ官方链接https://zoj.pintia.cn/problem-sets/91827364500/problems/91827365109 #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N = 8010; int a[N], colo

00后的博客 455

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

ZOJ 1610 Count the Colors【线段树】

Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.

wyjwyl的专栏 436

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

ZOJ 1610 Count the Colors 线段树 染色问题

做法:在udate之后可以直接把线段树上的信息映射到一个数组上考虑 #include #include #define left l,m,x<<1 #define right m+1,r,x<<1|1 const int LMT=16002; int cov[LMT<<2],seg[LMT],ans[LMT]; //映射法 void init(void) { memset(cov,-1,siz

uiiの技术随笔 760

【线段树】Count the Colors (zoj 1610)

Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB (zoj 1610) Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent on

Jiangzh_MZOI 761

zoj1610 Count the Colors 线段树

题目链接在这里 题目描述: 在一条直线上画不同颜色的线段,给出各线段的起点、终点和颜色,求画完之后,最终会有几种颜色,每个颜色有多少条线段。 思路分析: 我们用线段树保存各点的颜色,区间更新,最后query一下就好。 注意题目给的是线段的起点和终点,是连续的。如果想用离散的表示的话,就让起点+1,代表一段。 代码如下: 非结构体: #include &lt;cstdio&gt; ...

Joel 235

zoj1610Count the Colors【暴力 or 线段树】

ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on a line, some previously painted segments may be covered by some the

走一步再走一步 734

zoj 1610 Count the Colors 线段树

本地跑不起来交上去能过.. #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r

uuuuuu 506

zoj 1610 Count the Colors 线段树,成段更新染色

Count the ColorsTime Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu SubmitStatus Description Painting some colored segments on a line, some previously painted segments may

colorfulshark 1562

Count the Colors (ZOJ - 1610,离散化 + 线段树)

一.题目链接: ZOJ-1610 二.题目大意: 一条线上,端点编号为 [0,8e3]. 每次给出一段区间 和 一种颜色编号,在线上的这段区间染色. 问每种颜色出现的次数. 三.分析: 这道题(记为 Q1)与这道题(记为 Q2)不太一样 画个图理解一下: 可以看到对于 Q1 来说,[3, 4] 区间内为红色,但是节点 3 与 节点 4 相邻,此时不好判断 而 Q2 不存在...

The___Flash的博客 255

【线段树】Zoj 1610 Count the Colors

题意: 在一条线上绘制一些彩色的线段,某些先前绘制的线段可能会被后续的线段覆盖。 您的任务是计算最终可以看到的不同颜色的分段的数量。 解析: 用点 i+1 来表示线段[ i , i+1 ] #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int maxn = 8000 + 10; int t,m,n,a,b,c,q,k; string s; int su

weixin_44745441的博客 180

线段树之ZOJ1610 Count the Colors

成段替换的模型。 这一题告诉你的是要涂色的点的范围,而线段树内节点表示的区间的颜色(原谅我拙计的语文)。可以和POJ2528 对比,就能发现区别了。 #include #include #include #include #include #include #include #include #include #include #include #include #in

htw 267

线段树专题—ZOJ1610 Count the Colors

题意:给一个n,代表n次操作,接下来每次操作表示把[l。r]区间的线段涂成k的颜色当中,l,r,k的范围都是0到8000 分析:事实上就是拿线段树维护一段区间的颜色,整体用到的是线段树的区间更新把,可是会给人一种区间合并的错觉 注意:这题比較坑的是千万不能拿n建树,不然就会s...

aoe41606的博客 108
上一篇: 2018ACM/ICPC南京站网络赛G Lpl and Energy-saving Lamps(线段树)
下一篇: ICPC2018南京网络赛 AC Challenge(一维状压dp)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值