poj 2777 Count Color

题目连接

http://poj.org/problem?id=2777  

Count Color

Description

Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. 

There is a very long board with length L centimeter, L is a positive integer, so we can evenly divide the board into L segments, and they are labeled by 1, 2, ... L from left to right, each is 1 centimeter long. Now we have to color the board - one segment with only one color. We can do following two operations on the board: 

1. "C A B C" Color the board from segment A to segment B with color C. 
2. "P A B" Output the number of different colors painted between segment A and segment B (including). 

In our daily life, we have very few words to describe a color (red, green, blue, yellow…), so you may assume that the total number of different colors T is very small. To make it simple, we express the names of colors as color 1, color 2, ... color T. At the beginning, the board was painted in color 1. Now the rest of problem is left to your.

Input

 First line of input contains L (1 <= L <= 100000), T (1 <= T <= 30) and O (1 <= O <= 100000). Here O denotes the number of operations. Following O lines, each contains "C A B C" or "P A B" (here A, B, C are integers, and A may be larger than B) as an operation defined previously.

Output

Ouput results of the output operation in order, each line contains a number.

Sample Input

2 2 4
C 1 1 2
P 1 2
C 2 2 2
P 1 2

Sample Output

2
1

线段树+lazy标记。
我用0表示杂色,非0表示纯色,用color数组记录出现的颜色。
具体如下。。

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
using std::set;
using std::sort;
using std::pair;
using std::swap;
using std::queue;
using std::multiset;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr, val) memset(arr, val, sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = 100000;
const int INF = 0x3f3f3f3f;
typedef unsigned long long ull;
#define lc (root<<1)
#define rc (root<<1|1)
#define mid ((l + r)>>1)
bool color[40];
struct SegTree {
	struct Node { int c; }seg[N << 2];
	inline void push_down(int root) {
		if (seg[root].c > 0) {
			seg[lc].c = seg[rc].c = seg[root].c;
			seg[root].c = 0;
		}
	}
	inline void update(int root, int l, int r, int x, int y, int col) {
		if (x > r || y < l) return;
		if (x <= l && y >= r) {
			seg[root].c = col;
			return;
		}
		push_down(root);
		update(lc, l, mid, x, y, col);
		update(rc, mid + 1, r, x, y, col);
	}
	inline void built(int root, int l, int r) {
		seg[root].c = 1;
		if (l == r) return;
		built(lc, l, mid);
		built(rc, mid + 1, r);
	}
	inline void query(int root, int l, int r, int x, int y) {
		if (x > r || y < l) return;
		if (seg[root].c > 0) {
			color[seg[root].c] = true;
			return;
		}
		query(lc, l, mid, x, y);
		query(rc, mid + 1, r, x, y);
	}
}work;
int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w+", stdout);
#endif
	char ch;
	int n, q, t, c, x, y;
	while (~scanf("%d %d %d", &n, &t, &q)) {
		work.built(1, 1, n);
		while (q--) {
			getchar();
			scanf("%c", &ch);
			if ('C' == ch) {
				scanf("%d %d %d", &x, &y, &c);
				work.update(1, 1, n, x, y, c);
			} else {
				scanf("%d %d", &x, &y);
				memset(color, false, sizeof(color));
				work.query(1, 1, n, x, y);
				int tot = 0;
				for (int i = 1; i < t + 2; i++) { if (color[i]) tot++; }
				printf("%d\n", tot);
			}
		}
	}
	return 0;
}

转载于:https://www.cnblogs.com/GadyPu/p/4867355.html

网表导入virtuoso后发现pg pin忘记connect_pg_net/globalNetConnect怎么办? 数模混合项目中经常需要一些需要到virtuoso去连接的线,比如IO上的pg和一些信号线,除了在pr工作中设置skip route之外还需要做好net的赋值,告诉工具虽然我没在物理上有连接,但是实际上应该连什么net,这部分提现在网表里。在Default Net Name中也填写net name,因为这个net需要做global操作,即在顶层定义这个net,所以需要在net name后加个!打开schematic,删除指定cell pin所接net的label。 阅读详情

相关推荐

DolphinScheduler工作流中ChunJun任务保存失败的深度解析与实战修复

本文深度解析了在DolphinScheduler工作流中创建ChunJun任务时遭遇“parameter invalid”保存失败的普遍问题。其根源在于前端表单的`customConfig`参数默认值与后端校验逻辑不匹配。文章提供了两种实战修复方案:一是修改前端源码并重新编译,二是热更新已部署的JS文件,并对比了其适用场景与风险,帮助用户彻底解决此集成障碍。

weixin_29010003的博客 405

POJ 2777 Count Color

POJ 2777 Count Color 题目链接 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. There is a very long board with length L centimeter, L is a positive integer

旺崽的博客 2868

Tesseract in Java - Intellij IDEA对Tess4J的配置和使用

最近要弄OCR,搜到这个,官网全英文,很烦,看看有没有中文的博客介绍,擦,一个比一个奇葩,还是自己按照官方的来吧,外网慢的很,传到csdn给大家下载。中文训练库下载地址: http://download.csdn.net/detail/d_dmelon/9916532Tess4J3.4下载地址: http://download.csdn.net/detail/d_dmelon/9916519安装

Lewis的博客 1万+

【题解】Count Color POJ - 2777 (线段树 区间染色)⭐⭐⭐

Count Color POJ - 2777 Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. There is a very long board with le...

Suprit's blog 807

保姆级避坑指南:在Ubuntu 18.04上搞定速腾Helios雷达驱动与fast-LIO2的完整配置流程

本文提供了一份详细的速腾Helios雷达与fast-LIO2在Ubuntu 18.04上的配置避坑指南,涵盖驱动安装、数据格式转换到建图全流程。特别针对常见编译错误和数据转换问题提供了解决方案,帮助开发者高效完成环境搭建与建图任务。

weixin_27252001的博客 119

新年美食鉴赏——基于注意力机制CBAM的美食101分类

新年美食鉴赏——基于注意力机制CBAM的美食101分类一、数据预处理1.数据集介绍2.读取标签3.统一命名4.整理图片路径5.划分训练集与验证集6.定义美食数据集二、注意力机制1.简介2.卷积块注意力网络——CBAM通道注意力模块CAM空间注意力模块SAM3.将通道、空间注意力模块合并三、基于卷积块注意力模块的ResNet-CBAM1.代码实现2.模型测试3.查看网络结构4.模型训练5.模型预测四、总结与升华个人简介 春节是一年当中最隆重、最盛大的节日,吃得最好的一餐可能就是年夜饭了,想想就很激动呢!随着新

zbp_12138的博客 1万+

线段树(hdu3308LCIS、poj2777Count Color

hdu3308 LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10830 Accepted Submission(s): 4632 Problem Description Given n integers. You have two operations: U A B: replace the Ath number by B. (

yxrzibinanhai的博客 296

MATLAB 与 STK 互联的两种连接方式详解

批量仿真推荐使用方法一;交互分析推荐使用方法二。可以根据具体任务灵活切换,也可以同时使用两种方式,提升建模与仿真的效率。

weixin_52370774的博客 1587

poj2777 Count Color

线段树+位运算,思路好

AaronPolaris 1157

我的世界模组开发——前言

避坑:在开发过程中一定不要过分依赖AI,虽说现在的人工智能很厉害,但是也有很大的弊端,很多AI生成的代码错误百出,还得自己修改,而且像deepseek这种AI的训练数据还停留在一年前,给出的maven仓库地址都是过时的甚至是错误的,开发模组就是要多学习,多看源码,这样开发模组的水平才能越来越高。总而言之,build.gradle文件在我的世界Forge模组开发中扮演了重要的角色,它定义了项目的构建过程、依赖关系和编译选项,为开发者提供了灵活而强大的构建工具。开发工具推荐使用idea,因为可以使用通灵义码。

qq_24992377的博客 2600

ultralytics.data.utils——utils.py子模块代码详读

ultralytics.data.utils——utils.py子模块代码详读

Together_CZ的博客 1734

POJ 2777 Count Color(线段树)

题目地址:POJ 2777 我去。。延迟标记写错了。标记到了叶子节点上。。。。这根本就没延迟嘛。。。怪不得一直TLE。。。 这题就是利用二进制来标记颜色的种类。然后利用或|这个符号来统计每个区间不同颜色种数。 代码如下: #include #include #include #include #include #include #include #include #incl

scf0920 1171

关于海康MVS软件显示速率低与1GB、相机丢包的设置优化

工控机主要应用与视觉检测!相机网线及工控机网口都是千兆的!设置完巨帧数和速度与双工(选择为全双工),显示速度低与1GB,不能够正常工作。C.LA-Properdes-Advanced-将RecerveBuffers更改为2048。E.LAN-属性-电源管理-取消选中允许计算机关闭此设备以保存电源。这种情况均为MVS设置不熟悉,可参照如下设置优化相应端口相机配置。D.局域网-属性-高级-将传输缓冲区更改为20484。B.LAN-属性-高级-将中断记录部分更改为执行。A.关闭采集控制帧速率控制。

米可的博客! 8864

POJ2777 Count Color

线段树 压位 Lazy标记

a free man 581

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

poj 2777 Count Color 线段树

题目大意:有一段长为L(1 C A B C ——将区间[A, B]涂为颜色C P A B —— 查询区间[A, B]间有多少种颜色 PS:初始时木板颜色为1;A不一定小于B。做题时需注意这两个地方。 解题思路: 首先,这是个更新区间,查询区间的问题,很容易想到要用线段树。那么接下来的工作就是线段树中需要哪些数据域来解决这个问题呢?一共有30种颜料,不多,但也不能每个节点开个数组

暮雨潇湘 1427

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Count Color poj 2777

题目链接:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29470 Accepted: 8800 Description Chosen ProblemSol

CSDN515的专栏 1171

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

POJ2777Count Color

POJ2777Count Color 标签:线段树 http://www.sakurasake.icoc.me/nd.jsp?id=8#_np=2_327 Time Limit: 1000MS Memory Limit: 65536K Description Chosen Problem Solving and Program

Welcome to yjjr's blog! 477

POJ2777 Count Color 线段树

POJ2777 Count Color 线段树Description一个长为L,颜色为1的木板,有操作为 1.C A B C 将[A,B]涂上C颜色 2.P A B 询问[A,b]不同颜色个数。Input第一行 L,T,O O为操作个数,T为颜色种类最大个数。 下面O行为操作。Output对应询问输出答案。Sample Input2 2 4 C 1 1 2 P 1 2 C 2 2 2 P 1

YJSheep 2689
上一篇: hdu 1053 Entropy
下一篇: poj 2785 4 Values whose Sum is 0
dong12276
博客等级 码龄13年 0粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址