ZOJ 1610 Count the Colors

大数据课程综合实验案例:网站用户行为分析 大数据课程综合实验案例1 案例简介1.1 案例目的1.2 适用对象1.3 时间安排1.4 预备知识1.5 硬件要求1.6 软件工具1.7 数据集1.8 案例任务1.9 实验步骤2 本地数据上传到数据仓库Hive2.1 实验数据集的下载2.2 数据集的预处理(1)删除文件第一行记录,即字段名称(2)对字段进行预处理(3)导入数据库3 Hive数据分析3.1 操作Hive3.2 简单查询分析3.3 查询条数统计分析3.4 关键字条件查询分析3.4.1 以关键字的存在区间为条件的查询3.4.2 关键字赋予给定值为 阅读详情

Count the Colors

https://vjudge.net/problem/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

C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 8000 + 10;

int color[MAXN];

struct node{
	int l, r, c;
}segTree[MAXN << 2];

void pushdown(int x)
{
	if(segTree[x].c != -1)
	{
		segTree[x << 1].c = segTree[x << 1 | 1].c = segTree[x].c;
		segTree[x].c = -1;
	}
}

void build(int x, int l, int r)
{
	segTree[x].l = l;
	segTree[x].r = r;
	if(l == r)
	{
		segTree[x].c = -1;
		return;
	}
	int mid = l + r >> 1;
	build(x << 1, l, mid);
	build(x << 1 | 1, mid + 1, r);
	segTree[x].c = -1;
}

void update(int x, int l, int r, int val)
{
	if(l <= segTree[x].l && segTree[x].r <= r)
	{
		segTree[x].c = val;
		return;
	}
	pushdown(x);
	int mid = segTree[x].l + segTree[x].r >> 1;
	if(r <= mid) update(x << 1, l, r, val);
	else if(l > mid) update(x << 1 | 1, l, r, val);
	else
	{
		update(x << 1, l, mid, val);
		update(x << 1 | 1, mid + 1, r, val);
	}
}

int query(int x, int l, int r)
{
	if(l <= segTree[x].l && segTree[x].r <= r)
		return segTree[x].c;
	pushdown(x);
	int mid = segTree[x].l + segTree[x].r >> 1;
	if(r <= mid) query(x << 1, l, r);
	else if(l > mid) query(x << 1 | 1, l, r);
	else
	{
		query(x << 1, l, mid);
		query(x << 1 | 1, mid + 1, r);
	}
}

int main()
{
	int n;
	int x, y, z;
	while(scanf("%d", &n) != EOF)
	{
		build(1, 0, 8000);
		int maxn = 0;
		for(int i = 0; i < n; i ++)
		{
			scanf("%d%d%d", &x, &y, &z);
			update(1, x, y - 1, z);
			maxn = max(maxn, y);
		}
		memset(color, 0, sizeof(color));
		int last = query(1, 0, 0), now;
		for(int i = 1; i <= maxn; i ++)
		{
			now = query(1, i, i);
			if(last != now && last != -1) color[last] ++;
			last = now;
		}
		for(int i = 0; i <= 8000; i ++)
		{
			if(color[i]) printf("%d %d\n", i, color[i]);
		}
		puts("");
	}
	return 0;
}
【VoxCPM2】在Windows上从零搭建VoxCPM2 语音生成和语音克隆AI算法 建议你了解清楚VoxCPM2,再来考虑是否需要自己在本地搭建。 阅读详情

相关推荐

ESP8266 进行HDLC解码,AX.25,APRS

/************************************************************** 函数名:aprs_wait_begin() 参 数:无 返回值:bool true=得到合法脉冲,false=未得到 说 明:等待第1个833us高脉冲,判断范围 730-930,其他忽略 ***************************************************************/ bool aprs_wait_begin(){ stati

蓝蓝的博客 1626

uva 1607 gates

构造解+二分

YHaX的博客 1312

HALCON实战:用两个工业相机实现无缝大视野拼接(附完整代码与避坑指南)

本文详细介绍了使用HALCON软件实现双工业相机图像无缝拼接的完整解决方案,涵盖硬件配置、相机标定、坐标系转换和图像拼接等关键步骤。通过高精度标定和矩阵变换技术,可构建大视野检测系统,适用于液晶面板、PCB等工业检测场景,显著提升检测效率和精度。

weixin_29050513的博客 190

报错should contain exactly one root element. if you are using v-if on multiple elements

标题写不下了 报错内容是should contain exactly one root element. if you are using v-if on multiple elements, use v-else-if to chain them instead. 上图 这个错误解决的方法就是组件中的template格式,内容外面没有套根节点,也就是包裹内容的最大那个容器,我的案例里是最外面的 ...

Haley_170的博客 702

用友U8 API开发实战:手把手教你使用API资源管理器完成单据操作

本文详细介绍了用友U8 API开发实战,重点讲解如何使用API资源管理器完成采购订单、销售出库单等核心业务单据的全生命周期管理。从开发环境搭建到单据查询、新增、修改、删除等基础操作,再到高级功能如审核状态管理、业务事件处理和自定义项扩展,帮助开发者快速掌握用友U8接口开发技巧,提升企业数字化转型效率。

weixin_28607671的博客 595

【具身算法】VLA算法-Diffusion Policy

《扩散策略:多模态机器人控制的新方法》摘要 本文提出了一种基于扩散模型的机器人控制策略(DiffusionPolicy),用于解决视觉运动控制中的多模态行为、高维动作空间和训练稳定性问题。该方法利用去噪扩散概率模型(DDPM)生成动作序列,通过迭代优化处理复杂动作分布,显著提升了性能。实验表明,在15项机器人操作任务中,扩散策略平均性能提升46.9%,有效解决了传统显式/隐式策略的局限性。其核心优势在于:1)优雅建模多模态动作分布;2)适应高维动作空间;3)训练过程稳定。未来工作将探索与强化学习的结合及计算

puzhinan7781的博客 1389

如何分享数据

How to share data with a statisticianThis is a guide for anyone who needs to share data with a statistician. The target audiences I have in mind are: Scientific collaborators who need statisticians to

GG的专栏 768

【100%通过率】华为OD机试真题 C++ 实现【水库蓄水问题】【2022.11 Q4 新题】

给定一个长度为 n 的整数数组height。数组的元素表示山的高度,选择两个元素作为水库的边界,求蓄水量的最大值并输出蓄水量最大时的边界下标(蓄水量相同时输出下标较近的)。

MISAYAONE的博客 1万+

13.7.31 Wed C(模拟)

      C - C Description 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 co...

Simone chou... 169

YOLOv5改进有效涨点目录 | 包含卷积、主干、检测头、注意力机制、Neck上百种创新机制

Hello,各位读者们好本专栏自开设两个月以来已经更新改进教程60余篇其中包含C2f、主干、检测头、注意力机制、Neck多种结构上创新,也有损失函数和一些细节点上的创新。同时本人一些讲解视频和包含我所有创新的YOLOv8文档并不能在优快云上传(所有的创新点都经过我的测试是可用的,得到该文件之后大家可以随意组合使用),所以会建立群的形式在内上传我的文件和视频我也会在群内不定期和大家交流回答大家问题,同时定期会更新一些文章的创新点(经过我融合测试后的,先到先得)。本专栏持续更新网络上的所有前沿文章。

Snu77的博客 3万+

AI穿透式智慧粮仓

本报告基于 2025-2026 年全国多地智慧粮储实践案例,系统分析了 "AI + 穿透式" 智慧粮储体系的技术架构、AI 算法应用、提质增效成效、区域差异化特点及未来发展趋势。该体系通过多模态感知、智能算法与管控平台的深度融合,实现粮食存储全流程精准感知、智能预警与科学调控,显著降低储粮损耗与运营成本,大幅提升储粮安全水平与管理效率。报告梳理了各地差异化实践路径,提出针对性发展建议,为推动我国粮食仓储高质量发展、筑牢国家粮食安全防线提供参考。

reset2021的博客 229

Count the Colors (线段树区间染色问题)

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...

ldu_商正昌的博客 900

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

ZOJ--1610-Count the Colors

题目链接:ZOJ--1610-Count the Colors 要注意 更新区间的时候 如果是 1 3 1 1 2 2 3 4 3 这种情况的时候应该是三种颜色 要注意 0 #include<iostream> #include<algorithm> #include<cmath> #include<cstri...

dianzanji4884的博客 145

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

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

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

qq_33437973的博客 232

假人有限元模型

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

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

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

Count the Colors (ZOJ-1610)

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 col...

菜鸡的博客 324

ZOJ1610 Count the Colors

思路:区间更新,另外千万不能拿n建树,不然就会segmentation fault,必须拿8000建树,也就是树是固定的 #include<bits/stdc++.h> #define fi first #define se second #define INF 0x3f3f3f3f #define ll long long #define ld long double #defi...

Endeavor_G的博客 310

ZOJ 1610 Count the Colors(线段覆盖着色:离散化)

ZOJ 1610 Count the Colors(线段着色:离散化) http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 题意:        给你n条[0,8000]范围内的带不同颜色的线段,问你最终该线段都有哪些颜色,且这些颜色分别出现了多少次(即在多少段线段内出现了)? 分析:        本题可以

code 1219

【ZOJ 1610】Count the Colors

问题描述 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.

Fallen_Angel001的博客 423

zoj1610——Count the Colors

题目大意:给一个分成n段的木板涂色,后序涂色可能会覆盖之前的涂色,问最终露出来的颜色和他们的段数 输入:(可以有很多case)             n(1             第i次涂色的左端点 右端点  所涂的颜色序号(共n次涂色各占一行,所有数据的范围都是 [0, 8000]) 输出:(每个case的输出中间有一个空行)             最终漏出的颜色序号  涂了它

tzyshiwolaogongya的博客 278

ZOJ1610Count the Colors

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. Inp...

Mr.zhou 235

ZOJ - 1610 Count the Colors

题目: 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. I...

qq_41998938的博客 226

ZOJ 1610 - Count the Colors

Count the ColorsTime Limit: 2 Seconds      Memory Limit: 65536 KB Paintingsome colored segments on a line, some previously painted segments may becovered by some the subsequent ones.Your task iscounti...

Change the world by program. 228
上一篇: HDU 1698 Just a Hook
下一篇: POJ 2528 Mayor's posters
剑气扬名
博客等级 码龄7年 24粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值