题解:qoj6504 Flowers Land 2

news/2025/10/3 15:20:29/文章来源:https://www.cnblogs.com/LUlululu1616/p/19124639

人类智慧题。

题意:给出一个由 \(0,1,2\) 组成的字符串,每次给出一个区间,使 \(a_i\leftarrow (a_i+1)\mod 3\) 或者询问区间能否通过删除相邻两项使得整个串被删除。

做法:

首先注意到每次一定删除一个奇数位置的一个偶数位置的。然后感觉应该是个线段树题,但是如果直接维护剩下了什么显然是很爆炸的,我们考虑我们现在想要一个东西,他有结合律,但是不满足交换律,否则我乱交换数目对就对了,这显然是不行的。

还真有这么个东西——矩阵,我们考虑直接随三个矩阵 \(A_0,A_1,A_2\) 出来,分别代表 \(0,1,2\) 在奇数位置的权,偶数位置为其逆,修改直接维护 \(+0,+1,+2\) 后的矩阵情况就可以。

实现的时候为了方便,我们可以直接用对合矩阵作为 \(A\),可以省去对奇偶的特判。

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 5e5 + 5, mod = 998244353;
int qpow(int x, int k, int p) {int res = 1;while(k) {if(k & 1)res = res * x % p;x = x * x % p, k >>= 1;}return res;
}
struct Matrix {int a[2][2], n;Matrix() {memset(a, 0, sizeof(a));}friend Matrix operator*(Matrix x, Matrix y) {Matrix ans; ans.n = x.n;for (int i = 0; i < x.n; i++)for (int j = 0; j < y.n; j++)for (int k = 0; k < x.n; k++)ans.a[i][j] = (ans.a[i][j] + x.a[i][k] * y.a[k][j] % mod) % mod;return ans;}friend bool operator==(Matrix x, Matrix y) {for (int i = 0; i < x.n; i++)for (int j = 0; j < y.n; j++)if(x.a[i][j] != y.a[i][j])return 0;return 1;}void build() {a[1][0] = (1 - a[0][0] * a[0][0] % mod + mod) % mod * qpow(a[0][1], mod - 2, mod) % mod;a[1][1] = mod - a[0][0];}void print() {for (int i = 0; i < 2; i++)for (int j = 0; j < 2; j++)cout << a[i][j] << (j == 1 ? '\n' : ' ');cout << endl;}
};
Matrix ide[3], org;
struct node {Matrix ans[3];friend node operator+(node x, node y) {return node{x.ans[0] * y.ans[0], x.ans[1] * y.ans[1], x.ans[2] * y.ans[2]};}
} ;
int n, m;
string s;
struct Segtree {node tr[maxn << 2];int tag[maxn << 2];void pushup(int t) {tr[t] = tr[t << 1] + tr[t << 1 | 1];}void build(int l, int r, int t) {if(l == r) {for (int cnt = 1, i = s[l] - '0'; cnt <= 3; i = (i + 1) % 3, cnt++)tr[t].ans[cnt - 1] = ide[i];return ;}int mid = l + r >> 1;build(l, mid, t << 1), build(mid + 1, r, t << 1 | 1);pushup(t);}void addtag(int t, int val) {node tp = {tr[t].ans[val], tr[t].ans[(1 + val) % 3], tr[t].ans[(2 + val) % 3]};for (int i = 0; i < 3; i++)tr[t].ans[i] = tp.ans[i];tag[t] = (tag[t] + val) % 3;}void pushdown(int t) {addtag(t << 1, tag[t]);addtag(t << 1 | 1, tag[t]);tag[t] = 0;}void update(int l, int r, int x, int y, int t) {if(x <= l && r <= y) {addtag(t, 1);return ;}int mid = l + r >> 1;pushdown(t);if(x <= mid)update(l, mid, x, y, t << 1);if(mid < y)update(mid + 1, r, x, y, t << 1 | 1);pushup(t);}Matrix query(int l, int r, int x, int y, int t) {if(x <= l && r <= y)return tr[t].ans[0];int mid = l + r >> 1;pushdown(t);if(y <= mid)return query(l, mid, x, y, t << 1);if(mid < x)return query(mid + 1, r, x, y, t << 1 | 1);return query(l, mid, x, y, t << 1) * query(mid + 1, r, x, y, t << 1 | 1);}
} tree;
void prepare() {ide[0].n = ide[1].n = ide[2].n = org.n = 2;org.a[0][0] = org.a[1][1] = 1;ide[0].a[0][0] = 1, ide[0].a[0][1] = 1231;ide[0].build();ide[1].a[0][0] = 123, ide[1].a[0][1] = 23094;ide[1].build();ide[2].a[0][0] = 2348, ide[2].a[0][1] = 98235;ide[2].build();
//	(ide[0] * ide[0]).print();tree.build(1, n, 1);
}
signed main() {cin >> n >> m >> s; s = ' ' + s;prepare();while(m--) {int op, l, r; cin >> op >> l >> r;if(op == 1)tree.update(1, n, l, r, 1);else {cout << (tree.query(1, n, l, r, 1) == org ? "Yes" : "No") << endl;//	tree.query(1, n, l, r, 1).print();}}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/926024.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Prophet

Prophet模型深度解析:从设计理念到数学原理 Prophet是Meta(原Facebook)为商业场景时间序列预测开发的工具,核心设计目标是解决传统时序模型(如ARIMA、SARIMA)的痛点——对非平稳数据鲁棒性差、需手动处理趋势/季…

详细介绍:Jenkins:持续集成和持续交付(CI/CD)工具

详细介绍:Jenkins:持续集成和持续交付(CI/CD)工具pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas&qu…

详细介绍:范式革命:RDMA 如何让网络成为 “分布式内存总线”

详细介绍:范式革命:RDMA 如何让网络成为 “分布式内存总线”2025-10-03 15:09 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !impor…

专业做家具的网站有哪些鹤峰网站制作

ArkTS语言入门 在学习ArkTS语言之前&#xff0c;我们首先需要一个能够编译并运行该语言的工具 DevEco Studio。 了解ArkTS ArkTS是OpenHarmony优选的主力应用开发语言。ArkTS围绕应用开发在TypeScript&#xff08;简称TS&#xff09;生态基础上做了进一步扩展&#xff0c;继…

大型活动临时组网的技术解析:如何构建高效稳定的通信网络

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

安徽省建设厅网站张天培16岁的做兼职在什么网站好

一、下载、编译 redis是以源码方式发行的&#xff0c;先下载源码&#xff0c;然后在linux下编译 1.1 http://www.redis.io/download 先到这里下载Stable稳定版&#xff0c;目前最新版本是2.8.17 1.2 上传到linux&#xff0c;然后运行以下命令解压 tar xzf redis-2.8.17.tar.gz …

长沙网站设计公司推荐wordpress相关网站

在 webpack 中&#xff0c;专注于处理 webpack 在编译过程中的某个特定的任务的功能模块&#xff0c;可以称为插件。它和 loader 有以下区别&#xff1a; 1loader 是一个转换器&#xff0c;将 A 文件进行编译成 B 文件&#xff0c;比如&#xff1a;将 A.less 转换为 A.css&…

查网站排名wordpress 站群

在上一篇文章中&#xff0c;我们介绍了&#xff0c;对于安全技术开发者&#xff0c;如何快速的基于 Rosetta 等隐私 AI 框架所提供的一系列接口&#xff0c;将自己的安全协议集成落地到上层的 AI 应用中来。在这一篇文章中&#xff0c;我们将介绍为了保护用户的隐私数据&#x…

抚顺网站开发招聘wordpress更改主题

文章目录1. html 部分2. js部分3. 拦截器部分4. 认证授权部分5. 控制层部分6. 工具类实现流程: 1.从reqest域中获取现在登陆的新sessionId 2.根据登陆的用户名从reqest域中获取已经登陆的老sessionId 3.判断老sessionId是否存在和新旧sessionId是否是否一致 如果一直返回当前用…

和水导学习的第二篇笔记

操作系统 操作系统的作用 将外部指令传给CPU 操作系统有什么 计算机有什么组成: 应用程序:便利生活,具体干活,和操作系统,人交互 操作系统:接收外部指令,控制硬件,和人,硬件,应用程序交互 硬件:操作数据,和…

微信公众号推文添加附件方法,1分钟学会!支持word,excel,pdf等适合招聘,公告,申请表等

微信公众号图文文章时,总会遇到带有附件的文章,但微信公众号本身并不具备直接上传附件的功能,那编辑者们是如何快速在微信公众号中添加office、pdf和word等附件,以供用户快速预览或保存使用的呢?微信公众号图文文…

社保在哪个网站做增员网站建设兼职挣多少钱

01.dns解析过程02.用户访问网站流程03.局域网电脑上网流程04.网站架构图解转载于:https://blog.51cto.com/qinbin/1954149

bMIND包本地安装

https://github.com/randel/MIND 下载code,下载下来是MIND-master.zip,本地R安装要求严格是“MIND-master.tar.gz” 格式转化: # 如果机器上有 git: cd /public/home/chidm/Downloads git clone https://github.com…

百度电商MultiAgent视频生成系统 - 详解

百度电商MultiAgent视频生成系统 - 详解2025-10-03 14:56 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block …

网络实践——基于epoll_ET工作、Reactor设计模式的HTTP服务 - 实践

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

为博客写遗言

写下这段文字的时候,内心是极挣扎的 可能是【数据删除】临近了,所以情感上的波动愈发强烈 不久后,就要和 cnblogs 说再见了,甚至是和电脑说再见了足足 249 篇博客,不舍、痛苦、伤感是难免的 博客快断更了,应当有…

2025国庆Day2

模拟赛 T1 简单题 离散化+差分即可 或者直接贪心 对可能成为答案的点计算删的区间并取min #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath>…

灵犀科技网站开发WordPress获取评论内容

5大安全产品全面升级&#xff0c;抢先了解&#xff1a;https://developer.aliyun.com/topic/securityapril 预约观看发布会&#xff1a;https://yq.aliyun.com/live/2670 新基建大势之下的物联网 近日&#xff0c;中央政治局常委会会议提出&#xff0c;加快发展5G、数据中心、…

新能源汽车整车电控环境详解!

新能源汽车整车电控环境详解!pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco"…

《吃透 C++ vector:从基础使用到核心接口实战指南》 - 指南

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …