统计颜色Count Color(POJ2777)题解
有一个长度为L厘米板,L是一个正整数,所以我们可以把它均匀地划分成L个部分,分别从左到右编号为1,2……L,每一个部分长度都为1厘米。现在我们必须给每个部分涂色,一个部分一种颜色,要求完成以下两种操作: 1.“C A B C1”:表示从A部分到B部分涂上C1颜色。 2.“P A B”:表示从A部分到B部分涂了几种颜色。 在我们的日常生活中,我们有非常少几种颜色(红色,绿色,蓝色,黄色...),所以你可以假设不同颜色的总数T是非常少。简单地说,我们表示颜色的名称为颜色1,颜色2,…..颜色T。最初时候,这个厘米版都涂成颜色1。
思路
由于颜色很少,所以说可以给他状态压缩成一个数。
也就是支持一下几个操作:
1.区间或上1<<k
2.查询区间的或值
然后用线段树做就可以了。
懒标记更新有一点不一样。
// C++ includes used for precompiling -*- C++ -*-// Copyright (C) 2003-2021 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>./** @file stdc++.h* This is an implementation file for a precompiled header.*/// 17.4.1.2 Headers// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cuchar>
#endif// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif#if __cplusplus >= 201402L
#include <shared_mutex>
#endif#if __cplusplus >= 201703L
#include <any>
#include <charconv>
// #include <execution>
#include <filesystem>
#include <optional>
#include <memory_resource>
#include <string_view>
#include <variant>
#endif#if __cplusplus > 201703L
#include <barrier>
#include <bit>
#include <compare>
#include <concepts>
#if __cpp_impl_coroutine
# include <coroutine>
#endif
#include <latch>
#include <numbers>
#include <ranges>
#include <span>
#include <stop_token>
#include <semaphore>
#include <source_location>
#include <syncstream>
#include <version>
#endif
//以上为万能头(POJ不能直接用,差评)
using namespace std;
const int N = 1000010;
int w[N];
struct owl {int l, r, v, q;
} tr[N * 4];
void pushup(int u) {tr[u].v = tr[u << 1].v | tr[u << 1 | 1].v;
}
void pushdown(int u) {tr[u].q = 0;tr[u << 1].q = tr[u << 1 | 1].q = 1;tr[u << 1].v = tr[u << 1 | 1].v = tr[u].v;
}
void build(int u, int l, int r) {tr[u].l = l;tr[u].r = r;if (l == r) {tr[u].v = 1;return ;}int mid = l + r >> 1;build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);pushup(u);
}
int query(int u, int l,int r) {if (tr[u].q){return tr[u].v;}if (tr[u].l >= l && tr[u].r <= r){return tr[u].v;}int mid = tr[u].l + tr[u].r >> 1;if (r <= mid){return query(u << 1,l,r);}else if (l > mid){return query(u << 1 | 1,l,r);}else{return query(u << 1,l,mid) | query(u << 1 | 1,mid + 1,r);}
}
void modify(int u, int l, int r, int v) {if (tr[u].q) {pushdown(u);}if (tr[u].l >= l && tr[u].r <= r) {tr[u].v = 1 << (v - 1);tr[u].q = 1;return ;}int mid = tr[u].l + tr[u].r >> 1;if (r <= mid){modify(u << 1,l,r,v);}else if (l > mid){modify(u << 1 | 1,l,r,v);}else{modify(u << 1,l,r,v);modify(u << 1 | 1,l,r,v);}pushup(u);
}
int main() {ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);int L,T,M;cin >> L >> T >> M;build(1,1,L);while (M -- ){char op;cin >>op;if (op == 'C'){int l,r,c;cin >> l >> r >> c;if (l> r){swap(l,r);}modify(1,l,r,c);}else{int l,r;cin >> l >> r;if (l > r){swap(l,r);}int t = query(1,l,r);
// cout << t << endl;int res = 0;for (int i = 0; i < T; i ++ ){if (t & ((1 << i))){res ++ ;}}cout << res << "\n";}}return 0;
}
相关文章:
统计颜色Count Color(POJ2777)题解
有一个长度为L厘米板,L是一个正整数,所以我们可以把它均匀地划分成L个部分,分别从左到右编号为1,2……L,每一个部分长度都为1厘米。现在我们必须给每个部分涂色,一个部分一种颜色,要求完成以下两…...
MySQL数据的增删改查(一)
目录 新增(create) 插入单条记录 插入多条记录 查询(retrieve) 查询所有列 查询特定列 查询字段为表达式 别名 去重 排序 按单列排序 按多列排序 使用表达式或别名排序 排序NULL值 条件查询 比较运算符 逻辑运算…...
国产文本编辑器EverEdit - 如何给小众语言开发大纲分析脚本
1 开发参考:小众语言如何开发大纲分析脚本 1.1 应用场景 在使用IDE进行代码开发时,代码中的变量、结构体、函数等,在大纲视图中都会显示出来,用户可以快速的了解当前文档的结构,以及快速跳转到函数、变量的声明位置。…...
【数据结构】线性数据结构——数组
1. 定义 数组是一种线性数据结构,由一组相同类型的元素组成,这些元素使用连续的内存空间存储。数组通过索引(下标)访问,每个元素的索引是固定的,从零开始递增。 2. 特点 顺序存储: 元素在内存…...
QT---------GUI程序设计基础
代码UI化设计(QT) 实例功能概述 假设我们要创建一个简单的计算器应用程序。该应用程序具有以下功能: 包含数字按钮(0-9)、操作符按钮(、-、*、/)、等于按钮()和清除按…...
2、Bert论文笔记
Bert论文 1、解决的问题2、预训练微调2.1预训练微调概念2.2深度双向2.3基于特征和微调(预训练下游策略) 3、模型架构4、输入/输出1.输入:2.输出:3.Learned Embeddings(学习嵌入)1. **Token Embedding**2. **Position Embedding**3…...
Linux之ARM(MX6U)裸机篇----7.蜂鸣器实验
一,蜂鸣器模块 封装步骤: ①初始化SNVS_TAMPER这IO复用为GPIO ②设置SNVS_TAMPPER这个IO的电气属性 ③初始化GPIO ④控制GPIO输出高低电平 bsp_beep.c: #include "bsp_beep.h" #include "cc.h"/* BEEP初始化 */ void beep_init…...
Zabbix 监控平台 添加监控目标主机
Zabbix监控平台是一个企业级开源解决方案,用于分布式系统监视和网络监视。它由Zabbix Server和可选组件Zabbix Agent组成,通过C/S模式(客户端-服务器模型)采集数据,并通过B/S模式(浏览器-服务器模型&#x…...
SpringCloud整合skywalking实现链路追踪和日志采集
1.部署skywalking https://blog.csdn.net/qq_40942490/article/details/144701194 2.添加依赖 <!-- 日志采集 --><dependency><groupId>org.apache.skywalking</groupId><artifactId>apm-toolkit-logback-1.x</artifactId><version&g…...
html文件通过script标签引入外部js文件,但没正确加载的原因
移动端H5应用,html文件通过script标签引入外部js文件,但没正确加载,在移动设备上难以排查。通过PC浏览器打开,发现js被阻止了:blocked:mixed-content。 原因在于: “blocked:mixed - content” 是浏览器的…...
OpenHarmony开发板环境搭建
程序员Feri一名12年的程序员,做过开发带过团队创过业,擅长Java相关开发、鸿蒙开发、人工智能等,专注于程序员搞钱那点儿事,希望在搞钱的路上有你相伴!君志所向,一往无前! 0.OpenHarmony 0.1 OpenHarmony OpenHarmony是一款面向全场景、全连接、全智能的…...
【Rust自学】7.6. 将模块拆分为不同文件
喜欢的话别忘了点赞、收藏加关注哦(加关注即可阅读全文),对接下来的教程有兴趣的可以关注专栏。谢谢喵!(・ω・) 7.6.1. 将模块的内容移动到其他文件 如果在模块定义时模块名后边跟的是;而不是代码块&#…...
Python入门:8.Python中的函数
引言 在编写程序时,函数是一种强大的工具。它们可以将代码逻辑模块化,减少重复代码的编写,并提高程序的可读性和可维护性。无论是初学者还是资深开发者,深入理解函数的使用和设计都是编写高质量代码的基础。本文将从基础概念开始…...
MySQL什么情况下会加间隙锁?
目录 一、使用范围条件查询 二、唯一索引的范围查询 三、普通索引的查询 四、间隙锁的锁定规则 五、间隙锁的影响 间隙锁(Gap Lock)是MySQL中的一种锁机制,主要用于防止幻读现象。在MySQL的InnoDB存储引擎中,当事务隔离级别设置为可重复读(Repeatable Read)时,间隙…...
【服务器开发及部署】code-server 显示git graph
在开发一些linux上的内容的时候进程需要在开发机和生产部署上花费大量的时间。 为了解决上述问题,我们今天介绍一款在服务上开发的思路 git + code server + 宝塔 其中需要处理一些问题,此处都有交代 步骤 安装宝塔安装code-server配置插件配置浏览器处理的问题 git版本过低,…...
Linux 终端查看 nvidia 显卡型号
文章目录 写在前面1. 需求描述2. 实现方法方法一:方法二方法三: 参考链接 写在前面 自己的测试环境: Ubuntu20.04 1. 需求描述 Linux 终端查看 nvidia 显卡型号 2. 实现方法 方法一: 执行下列指令: sudo update…...
助你通过AI培训师中级考试的目录索引
嘿,各位看官!在您正式踏入接下来的知识小宇宙之前,咱先唠唠几句… 家人们,我跟你们说,我脑一热报名了那个 AI 培训师考试。本想着开启一场知识的奇幻之旅,结果呢,学视频内容的时候,那…...
百度PaddleSpeech识别大音频文件报错
一、背景 公司前同事留下了一套语音识别项目,内部使用百度PaddleSpeech。在项目验收的时候发现无法识别大音频文件,但是可以识别小音频文件。 这套项目是通过python调用的百度PaddleSpeech,然后提供了restful接口,然后java项目可…...
Lucene 漏洞历险记:修复损坏的索引异常
作者:来自 Elastic Benjamin Trent 有时,一行代码需要几天的时间才能写完。在这里,我们可以看到工程师在多日内调试代码以修复潜在的 Apache Lucene 索引损坏的痛苦。 做好准备 这篇博客与往常不同。它不是对新功能或教程的解释。这是关于花…...
RabbitMQ基础篇之快速入门
文章目录 一、目标需求二、RabbitMQ 控制台操作步骤1.创建队列2.交换机概述3.向交换机发送消息4.结果分析5.消息丢失原因 三、绑定交换机与队列四、测试消息发送五、消息查看六、结论 一、目标需求 新建队列:创建 hello.queue1 和 hello.queue2 两个队列。消息发送…...
<6>-MySQL表的增删查改
目录 一,create(创建表) 二,retrieve(查询表) 1,select列 2,where条件 三,update(更新表) 四,delete(删除表…...
关于iview组件中使用 table , 绑定序号分页后序号从1开始的解决方案
问题描述:iview使用table 中type: "index",分页之后 ,索引还是从1开始,试过绑定后台返回数据的id, 这种方法可行,就是后台返回数据的每个页面id都不完全是按照从1开始的升序,因此百度了下,找到了…...
定时器任务——若依源码分析
分析util包下面的工具类schedule utils: ScheduleUtils 是若依中用于与 Quartz 框架交互的工具类,封装了定时任务的 创建、更新、暂停、删除等核心逻辑。 createScheduleJob createScheduleJob 用于将任务注册到 Quartz,先构建任务的 JobD…...
12.找到字符串中所有字母异位词
🧠 题目解析 题目描述: 给定两个字符串 s 和 p,找出 s 中所有 p 的字母异位词的起始索引。 返回的答案以数组形式表示。 字母异位词定义: 若两个字符串包含的字符种类和出现次数完全相同,顺序无所谓,则互为…...
Hive 存储格式深度解析:从 TextFile 到 ORC,如何选对数据存储方案?
在大数据处理领域,Hive 作为 Hadoop 生态中重要的数据仓库工具,其存储格式的选择直接影响数据存储成本、查询效率和计算资源消耗。面对 TextFile、SequenceFile、Parquet、RCFile、ORC 等多种存储格式,很多开发者常常陷入选择困境。本文将从底…...
【Nginx】使用 Nginx+Lua 实现基于 IP 的访问频率限制
使用 NginxLua 实现基于 IP 的访问频率限制 在高并发场景下,限制某个 IP 的访问频率是非常重要的,可以有效防止恶意攻击或错误配置导致的服务宕机。以下是一个详细的实现方案,使用 Nginx 和 Lua 脚本结合 Redis 来实现基于 IP 的访问频率限制…...
CVPR2025重磅突破:AnomalyAny框架实现单样本生成逼真异常数据,破解视觉检测瓶颈!
本文介绍了一种名为AnomalyAny的创新框架,该方法利用Stable Diffusion的强大生成能力,仅需单个正常样本和文本描述,即可生成逼真且多样化的异常样本,有效解决了视觉异常检测中异常样本稀缺的难题,为工业质检、医疗影像…...
jdbc查询mysql数据库时,出现id顺序错误的情况
我在repository中的查询语句如下所示,即传入一个List<intager>的数据,返回这些id的问题列表。但是由于数据库查询时ID列表的顺序与预期不一致,会导致返回的id是从小到大排列的,但我不希望这样。 Query("SELECT NEW com…...
Python学习(8) ----- Python的类与对象
Python 中的类(Class)与对象(Object)是面向对象编程(OOP)的核心。我们可以通过“类是模板,对象是实例”来理解它们的关系。 🧱 一句话理解: 类就像“图纸”,对…...
虚幻基础:角色旋转
能帮到你的话,就给个赞吧 😘 文章目录 移动组件使用控制器所需旋转:组件 使用 控制器旋转将旋转朝向运动:组件 使用 移动方向旋转 控制器旋转和移动旋转 缺点移动旋转:必须移动才能旋转,不移动不旋转控制器…...
