当前位置: 首页 > news >正文

统计颜色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厘米板&#xff0c;L是一个正整数&#xff0c;所以我们可以把它均匀地划分成L个部分&#xff0c;分别从左到右编号为1&#xff0c;2……L&#xff0c;每一个部分长度都为1厘米。现在我们必须给每个部分涂色&#xff0c;一个部分一种颜色&#xff0c;要求完成以下两…...

MySQL数据的增删改查(一)

目录 新增&#xff08;create&#xff09; 插入单条记录 插入多条记录 查询&#xff08;retrieve&#xff09; 查询所有列 查询特定列 查询字段为表达式 别名 去重 排序 按单列排序 按多列排序 使用表达式或别名排序 排序NULL值 条件查询 比较运算符 逻辑运算…...

国产文本编辑器EverEdit - 如何给小众语言开发大纲分析脚本

1 开发参考&#xff1a;小众语言如何开发大纲分析脚本 1.1 应用场景 在使用IDE进行代码开发时&#xff0c;代码中的变量、结构体、函数等&#xff0c;在大纲视图中都会显示出来&#xff0c;用户可以快速的了解当前文档的结构&#xff0c;以及快速跳转到函数、变量的声明位置。…...

【数据结构】线性数据结构——数组

1. 定义 数组是一种线性数据结构&#xff0c;由一组相同类型的元素组成&#xff0c;这些元素使用连续的内存空间存储。数组通过索引&#xff08;下标&#xff09;访问&#xff0c;每个元素的索引是固定的&#xff0c;从零开始递增。 2. 特点 顺序存储&#xff1a; 元素在内存…...

QT---------GUI程序设计基础

代码UI化设计&#xff08;QT&#xff09; 实例功能概述 假设我们要创建一个简单的计算器应用程序。该应用程序具有以下功能&#xff1a; 包含数字按钮&#xff08;0-9&#xff09;、操作符按钮&#xff08;、-、*、/&#xff09;、等于按钮&#xff08;&#xff09;和清除按…...

2、Bert论文笔记

Bert论文 1、解决的问题2、预训练微调2.1预训练微调概念2.2深度双向2.3基于特征和微调&#xff08;预训练下游策略&#xff09; 3、模型架构4、输入/输出1.输入&#xff1a;2.输出&#xff1a;3.Learned Embeddings(学习嵌入)1. **Token Embedding**2. **Position Embedding**3…...

Linux之ARM(MX6U)裸机篇----7.蜂鸣器实验

一&#xff0c;蜂鸣器模块 封装步骤&#xff1a; ①初始化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监控平台是一个企业级开源解决方案&#xff0c;用于分布式系统监视和网络监视。它由Zabbix Server和可选组件Zabbix Agent组成&#xff0c;通过C/S模式&#xff08;客户端-服务器模型&#xff09;采集数据&#xff0c;并通过B/S模式&#xff08;浏览器-服务器模型&#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应用&#xff0c;html文件通过script标签引入外部js文件&#xff0c;但没正确加载&#xff0c;在移动设备上难以排查。通过PC浏览器打开&#xff0c;发现js被阻止了&#xff1a;blocked:mixed-content。 原因在于&#xff1a; “blocked:mixed - content” 是浏览器的…...

OpenHarmony开发板环境搭建

程序员Feri一名12年的程序员,做过开发带过团队创过业,擅长Java相关开发、鸿蒙开发、人工智能等,专注于程序员搞钱那点儿事,希望在搞钱的路上有你相伴&#xff01;君志所向,一往无前&#xff01; 0.OpenHarmony 0.1 OpenHarmony OpenHarmony是一款面向全场景、全连接、全智能的…...

【Rust自学】7.6. 将模块拆分为不同文件

喜欢的话别忘了点赞、收藏加关注哦&#xff08;加关注即可阅读全文&#xff09;&#xff0c;对接下来的教程有兴趣的可以关注专栏。谢谢喵&#xff01;(&#xff65;ω&#xff65;) 7.6.1. 将模块的内容移动到其他文件 如果在模块定义时模块名后边跟的是;而不是代码块&#…...

Python入门:8.Python中的函数

引言 在编写程序时&#xff0c;函数是一种强大的工具。它们可以将代码逻辑模块化&#xff0c;减少重复代码的编写&#xff0c;并提高程序的可读性和可维护性。无论是初学者还是资深开发者&#xff0c;深入理解函数的使用和设计都是编写高质量代码的基础。本文将从基础概念开始…...

MySQL什么情况下会加间隙锁?

目录 一、使用范围条件查询 二、唯一索引的范围查询 三、普通索引的查询 四、间隙锁的锁定规则 五、间隙锁的影响 间隙锁(Gap Lock)是MySQL中的一种锁机制,主要用于防止幻读现象。在MySQL的InnoDB存储引擎中,当事务隔离级别设置为可重复读(Repeatable Read)时,间隙…...

【服务器开发及部署】code-server 显示git graph

在开发一些linux上的内容的时候进程需要在开发机和生产部署上花费大量的时间。 为了解决上述问题,我们今天介绍一款在服务上开发的思路 git + code server + 宝塔 其中需要处理一些问题,此处都有交代 步骤 安装宝塔安装code-server配置插件配置浏览器处理的问题 git版本过低,…...

Linux 终端查看 nvidia 显卡型号

文章目录 写在前面1. 需求描述2. 实现方法方法一&#xff1a;方法二方法三&#xff1a; 参考链接 写在前面 自己的测试环境&#xff1a; Ubuntu20.04 1. 需求描述 Linux 终端查看 nvidia 显卡型号 2. 实现方法 方法一&#xff1a; 执行下列指令&#xff1a; sudo update…...

助你通过AI培训师中级考试的目录索引

嘿&#xff0c;各位看官&#xff01;在您正式踏入接下来的知识小宇宙之前&#xff0c;咱先唠唠几句… 家人们&#xff0c;我跟你们说&#xff0c;我脑一热报名了那个 AI 培训师考试。本想着开启一场知识的奇幻之旅&#xff0c;结果呢&#xff0c;学视频内容的时候&#xff0c;那…...

百度PaddleSpeech识别大音频文件报错

一、背景 公司前同事留下了一套语音识别项目&#xff0c;内部使用百度PaddleSpeech。在项目验收的时候发现无法识别大音频文件&#xff0c;但是可以识别小音频文件。 这套项目是通过python调用的百度PaddleSpeech&#xff0c;然后提供了restful接口&#xff0c;然后java项目可…...

Lucene 漏洞历险记:修复损坏的索引异常

作者&#xff1a;来自 Elastic Benjamin Trent 有时&#xff0c;一行代码需要几天的时间才能写完。在这里&#xff0c;我们可以看到工程师在多日内调试代码以修复潜在的 Apache Lucene 索引损坏的痛苦。 做好准备 这篇博客与往常不同。它不是对新功能或教程的解释。这是关于花…...

RabbitMQ基础篇之快速入门

文章目录 一、目标需求二、RabbitMQ 控制台操作步骤1.创建队列2.交换机概述3.向交换机发送消息4.结果分析5.消息丢失原因 三、绑定交换机与队列四、测试消息发送五、消息查看六、结论 一、目标需求 新建队列&#xff1a;创建 hello.queue1 和 hello.queue2 两个队列。消息发送…...

synchronized 学习

学习源&#xff1a; https://www.bilibili.com/video/BV1aJ411V763?spm_id_from333.788.videopod.episodes&vd_source32e1c41a9370911ab06d12fbc36c4ebc 1.应用场景 不超卖&#xff0c;也要考虑性能问题&#xff08;场景&#xff09; 2.常见面试问题&#xff1a; sync出…...

Appium+python自动化(十六)- ADB命令

简介 Android 调试桥(adb)是多种用途的工具&#xff0c;该工具可以帮助你你管理设备或模拟器 的状态。 adb ( Android Debug Bridge)是一个通用命令行工具&#xff0c;其允许您与模拟器实例或连接的 Android 设备进行通信。它可为各种设备操作提供便利&#xff0c;如安装和调试…...

vscode(仍待补充)

写于2025 6.9 主包将加入vscode这个更权威的圈子 vscode的基本使用 侧边栏 vscode还能连接ssh&#xff1f; debug时使用的launch文件 1.task.json {"tasks": [{"type": "cppbuild","label": "C/C: gcc.exe 生成活动文件"…...

渗透实战PortSwigger靶场-XSS Lab 14:大多数标签和属性被阻止

<script>标签被拦截 我们需要把全部可用的 tag 和 event 进行暴力破解 XSS cheat sheet&#xff1a; https://portswigger.net/web-security/cross-site-scripting/cheat-sheet 通过爆破发现body可以用 再把全部 events 放进去爆破 这些 event 全部可用 <body onres…...

《用户共鸣指数(E)驱动品牌大模型种草:如何抢占大模型搜索结果情感高地》

在注意力分散、内容高度同质化的时代&#xff0c;情感连接已成为品牌破圈的关键通道。我们在服务大量品牌客户的过程中发现&#xff0c;消费者对内容的“有感”程度&#xff0c;正日益成为影响品牌传播效率与转化率的核心变量。在生成式AI驱动的内容生成与推荐环境中&#xff0…...

学校招生小程序源码介绍

基于ThinkPHPFastAdminUniApp开发的学校招生小程序源码&#xff0c;专为学校招生场景量身打造&#xff0c;功能实用且操作便捷。 从技术架构来看&#xff0c;ThinkPHP提供稳定可靠的后台服务&#xff0c;FastAdmin加速开发流程&#xff0c;UniApp则保障小程序在多端有良好的兼…...

【快手拥抱开源】通过快手团队开源的 KwaiCoder-AutoThink-preview 解锁大语言模型的潜力

引言&#xff1a; 在人工智能快速发展的浪潮中&#xff0c;快手Kwaipilot团队推出的 KwaiCoder-AutoThink-preview 具有里程碑意义——这是首个公开的AutoThink大语言模型&#xff08;LLM&#xff09;。该模型代表着该领域的重大突破&#xff0c;通过独特方式融合思考与非思考…...

【算法训练营Day07】字符串part1

文章目录 反转字符串反转字符串II替换数字 反转字符串 题目链接&#xff1a;344. 反转字符串 双指针法&#xff0c;两个指针的元素直接调转即可 class Solution {public void reverseString(char[] s) {int head 0;int end s.length - 1;while(head < end) {char temp …...

Robots.txt 文件

什么是robots.txt&#xff1f; robots.txt 是一个位于网站根目录下的文本文件&#xff08;如&#xff1a;https://example.com/robots.txt&#xff09;&#xff0c;它用于指导网络爬虫&#xff08;如搜索引擎的蜘蛛程序&#xff09;如何抓取该网站的内容。这个文件遵循 Robots…...

return this;返回的是谁

一个审批系统的示例来演示责任链模式的实现。假设公司需要处理不同金额的采购申请&#xff0c;不同级别的经理有不同的审批权限&#xff1a; // 抽象处理者&#xff1a;审批者 abstract class Approver {protected Approver successor; // 下一个处理者// 设置下一个处理者pub…...