codeforces580E. Kefa and Watch

〔重庆理工大学〕大学物理实验--变温霍耳效应及其参数测定 每个老师要求不同,实验报告内容和数据仅供参考。 阅读详情

传送门:http://codeforces.com/problemset/problem/580/E


E. Kefa and Watch
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering by the road. As he came nearer he understood that it was a watch. He decided to take it to the pawnbroker to earn some money.

The pawnbroker said that each watch contains a serial number represented by a string of digits from 0 to 9, and the more quality checks this number passes, the higher is the value of the watch. The check is defined by three positive integers l, r and d. The watches pass a check if a substring of the serial number from l to r has period d. Sometimes the pawnbroker gets distracted and Kefa changes in some substring of the serial number all digits to c in order to increase profit from the watch.

The seller has a lot of things to do to begin with and with Kefa messing about, he gave you a task: to write a program that determines the value of the watch.

Let us remind you that number x is called a period of string s (1 ≤ x ≤ |s|), if si  =  si + x for all i from 1 to |s|  -  x.

Input

The first line of the input contains three positive integers n, m and k (1 ≤ n ≤ 105, 1 ≤ m + k ≤ 105) — the length of the serial number, the number of change made by Kefa and the number of quality checks.

The second line contains a serial number consisting of n digits.

Then m + k lines follow, containing either checks or changes.

The changes are given as 1 l r с (1 ≤ l ≤ r ≤ n, 0 ≤ c ≤ 9). That means that Kefa changed all the digits from the l-th to the r-th to be c.

The checks are given as 2 l r d (1 ≤ l ≤ r ≤ n, 1 ≤ d ≤ r - l + 1).

Output

For each check on a single line print "YES" if the watch passed it, otherwise print "NO".

Sample test(s)
input
3 1 2
112
2 2 3 1
1 1 3 8
2 1 2 1
output
NO
YES
input
6 2 3
334934
2 2 5 2
1 4 4 3
2 1 6 3
1 2 3 8
2 3 6 1
output
NO
YES
NO
Note

In the first sample test two checks will be made. In the first one substring "12" is checked on whether or not it has period 1, so the answer is "NO". In the second one substring "88", is checked on whether or not it has period 1, and it has this period, so the answer is "YES".

In the second statement test three checks will be made. The first check processes substring "3493", which doesn't have period 2. Before the second check the string looks as "334334", so the answer to it is "YES". And finally, the third check processes substring "8334", which does not have period 1.

思路:首先对于第一种操作,可以用线段树维护哈希值,覆盖就打标记。

而对于询问,怎样快速判定一个字符串是否循环节为D呢?

充要条件就是len<=d(这个要记得写特判)或者s[1,len-d]==s[d,len]

为什么可以这样判呢,这很简单

我们把字符串分成n段,每段长为d,错开一段后比较若相等,那每段就相等了,于是循环节为d

于是用线段树维护一下就可以了。

#include<cstdio>
#include<cstring>
#include<algorithm>
#define fi first
#define se second
#define PI pair<long long,long long>
#define mp(a,b) make_pair(a,b)
#define ls (p<<1)
#define rs ((p<<1)|1)
#define mid ((l+r)>>1)
const int mod1=573292817,mod2=1e9+7,base1=233,base2=2333,maxn=100010,maxt=maxn<<3;
typedef long long ll;
using namespace std;
int n,m,k;char s[maxn];
ll pow1[maxn],pow2[maxn],sp1[maxn],sp2[maxn];
struct node{ll v1,v2;int cov,len;};
struct Segment_Tree{
	node t[maxt];
	void add_cov(int p,int c){
		t[p].cov=c;
		t[p].v1=c*sp1[t[p].len-1]%mod1;
		t[p].v2=c*sp2[t[p].len-1]%mod2;
	}
	void down(int p){if (t[p].cov!=-1) add_cov(ls,t[p].cov),add_cov(rs,t[p].cov),t[p].cov=-1;}
	node connect(node a,node b){
		int len=a.len+b.len;
		ll v1=(a.v1*pow1[b.len]+b.v1)%mod1;
		ll v2=(a.v2*pow2[b.len]+b.v2)%mod2;
		return (node){v1,v2,-1,len};
	}
	void update(int p){
		t[p].v1=(t[ls].v1*pow1[t[rs].len]%mod1+t[rs].v1)%mod1;
		t[p].v2=(t[ls].v2*pow2[t[rs].len]%mod2+t[rs].v2)%mod2;
	}
	void build(int p,int l,int r){
		t[p].len=r-l+1,t[p].cov=-1;
		if (l==r){t[p].v1=t[p].v2=s[l]-'0';return;}
		build(ls,l,mid),build(rs,mid+1,r);
		update(p);
	}
	void modify(int p,int l,int r,int a,int b,int c){		
		if (l==a&&r==b){add_cov(p,c);return;}
		down(p);
		if (b<=mid) modify(ls,l,mid,a,b,c);
		else if (a>mid) modify(rs,mid+1,r,a,b,c);
		else modify(ls,l,mid,a,mid,c),modify(rs,mid+1,r,mid+1,b,c);
		update(p);
	}
	node query(int p,int l,int r,int a,int b){
		if (l==a&&r==b){return t[p];}
		down(p);node ans;
		if (b<=mid) ans=query(ls,l,mid,a,b);
		else if (a>mid) ans=query(rs,mid+1,r,a,b);
		else ans=connect(query(ls,l,mid,a,mid),query(rs,mid+1,r,mid+1,b));
		//printf("%d %d %d %d %lld %lld\n",l,r,a,b,ans.v1,ans.v2);
		return ans;
	}
	PI query(int a,int b){node ans=query(1,1,n,a,b);return mp(ans.v1,ans.v2);}
}T;

void init(){
	scanf("%d%d%d%s",&n,&m,&k,s+1),m=m+k;
	pow1[0]=pow2[0]=sp1[0]=sp2[0]=1;
	for (int i=1;i<=n+5;i++){
		pow1[i]=pow1[i-1]*base1%mod1;
		pow2[i]=pow2[i-1]*base2%mod2;
		sp1[i]=(sp1[i-1]+pow1[i])%mod1;
		sp2[i]=(sp2[i-1]+pow2[i])%mod2;
	}
	T.build(1,1,n);
}
void work(){
	for (int i=1,op,a,b,c;i<=m;i++){
		scanf("%d%d%d%d",&op,&a,&b,&c);
		if (op==1) T.modify(1,1,n,a,b,c);
		else{
			if (b-a+1<=c){puts("YES");continue;}
			else puts(T.query(a,b-c)==T.query(a+c,b)?"YES":"NO");
			//for (int i=a;i<=b-c;i++) printf("%lld",T.query(i,i));puts("");
			//for (int i=a+c;i<=b;i++) printf("%lld",T.query(i,i));puts("");
			//printf("%lld %lld\n",T.query(a,b-c).fi,T.query(a+c,b).fi);
		}
	}
}
int main(){
	init(),work();
	return 0;
}
/*
20 1 2
34075930750342906718
2 1 20 20
1 1 20 6
2 1 20 1
*/



YOLOv13改进策略【小目标改进】| Shape-NWD:融合改进,结合Shape-IoU和NWD 更好地适应小目标特性 Bw−wgt2h−hgt2weight2Bweight2w−wgt​2h−hgt​2​其中weight2weight = 2weight2。 阅读详情

相关推荐

FOC电机控制实战:增量式编码器零位校准的5个关键步骤(附STM32代码)

本文详细解析了FOC电机控制中增量式编码器零位校准的5个关键步骤,包括电角度锁定、定时器计数清零、机械偏移角补偿等,并提供了STM32平台的实战代码。通过精准的零位校准,可显著提升电机控制系统的精度和稳定性,适用于工业伺服和机器人关节等高精度场景。

rum55的博客 618

Kefa and Watch 【CodeForces - 580E】【双值哈希hash+线段树】

题目链接   题意不难,给你一段长度为N的字符串,接下来就是有两种操作:一是更新一段区间让它们的值相同;二是问这个查询的区间是否符合f(i)==f(i+d),就是是否以d为周期长度。 思路:   确实想了挺久的,首先是字符串,这里就需要用到哈希的方式来处理,一开始哈希没弄好,错了,后来再重做时加上了取mod的操作然后就过了,还有,如何判断它是一个以d为周期长度的字符串呢?就利用f(i)==f...

既然弱小,就只顾变强就是了 366

Windows域账户无管理员权限也能装软件?3步搞定UAC设置(附安全提醒)

本文探讨了在Windows域环境中,如何通过配置用户账户控制(UAC)实现临时提权,让无管理员权限的域账户也能安装软件。文章详细介绍了三步走策略:临时加入本地管理员组、调整UAC行为以及至关重要的权限回收,并提供了脚本化部署方案与安全实践指南,旨在平衡企业IT管理的效率与安全。

fox11的博客 756

Kefa and Watch(字符串哈希线段树)

题目链接:Kefa and Watch 大致题意 给定一个长度为n, 且由数字组成的字符串, 有两种操作: ①把[l, r]区间的数字都变成c ②询问[l, r]区间的数字是否可以 以d为长度作为循环节. (如12345123, 可以以长度为5的12345作为循环节, 只不过最后的123不是完整的循环节) 解题思路 拿到这个题, 很快啊, 我们就发现是一个区间修改和区间询问的问题, 最先想到的就是我们的老朋友线段树. 分析: 对于操作①而言, 只需要维护一个懒标记即可. 对于操作②而言, 我们如何判断一个序

Fau的博客 254

STM32-DAC定时器触发三角波生成【频率与幅度精准控制】

本文详细介绍了STM32 DAC定时器触发三角波生成的原理与实现方法,涵盖硬件配置、频率与幅度精准控制技巧及代码实现。通过定时器触发DAC模块,可灵活调节三角波的频率和幅度,适用于信号发生器等高精度应用场景。

weixin_29161785的博客 452

数理金融学笔记 Chap2 二叉树模型Binomial

2 二叉树模型与期权定价 Binomial Model and Option Pricing 文章目录2 二叉树模型与期权定价 Binomial Model and Option Pricing单期二叉树模型 One-step Binomial Model风险与无风险资产单期二叉树模型与无套利条件无套利定价 No Arbitrage Pricing风险中性定价 Risk Neutral PricingDelta套期保值 Delta Hedging两期二叉树模型 Two-Step Binomial Model

weixin_66831131的博客 2387

CF 580E - Kefa and Watch (字符串双模哈希+线段树)

字符串哈希 +线段树 好题

qq_61305213的博客 313

uniapp(vue3):实现手机拍照或相册图片上传后给图片添加水印,uniapp实现多端图片上传、拍照上传自定义插入水印内容,调用手机摄像头打开相机并在周围悬挂自定义水印(支持文字水印/图片水印等)

uni-app,h5移动端网页,微信小程序,支付宝小程序,Android安卓,苹果ios,app,nvue,uni-app为图片添加自定义水印(解决生成图片不全问题),uniapp上传图片添加水印,uniapp H5实现手机拍照或相册上传图像并添加自定义水印,uniapp水印相机,uni-app为图片添加自定义水印,怎么在图片上加水印,图片水印,上传照片带水印,从相册选择图片加水印功能,拍完照片给图片加水印,添加照片水印,uniapp图片加水印,为图片添加自定义水印,uni-app上传图片并添加水印,上传图

✅ 精选推荐文章 3263

CF580E Kefa and Watch 题解

花了一个半个下午+半个晚上终于调出来了...... 0. 题面 长度为 \(n\) 的字符串,每个字符是 \(\mathtt{0} \sim \mathtt{9}\) 的数位,\(m + k\) 种操作: 格式为 1 l r c,表示将 \(l \sim r\) 赋值为 \(c\),保证 \(0 \le c \le 9\)。这种修改操作恰好 \(m\) 个。 格式为 2 l r d,表示...

qq_14886903的博客 233

【SigmaStudio】自定义算法组件之XML编写规范(一)

SigmaStudio生成自定义算法组件时,需要XML和DLB文件,本文主要记录XML文件的编码规范

liang_song的博客 1139

Playwright实战:打造绕过全维度前端反爬的无头浏览器爬虫(2026实战版)

Playwright绕过前端反爬的核心是模拟真实:真实的设备指纹、真实的行为轨迹、真实的网络请求;2025年前端反爬的核心检测维度是设备指纹+行为轨迹+网络请求,三者缺一不可;实战中需重点关注WebGL/Canvas指纹模拟、行为随机性、请求头完整性,这是绕过反爬的关键;性能优化需以“不触发反爬”为前提,优先选择浏览器复用、资源拦截,而非无限制并发。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 2094

Kefa and Watch CodeForces - 580E

题目链接 题意 一个1e5的字符串a, 1e5次操作 op l r cop\ l\ r\ cop l r c(下标从1开始) opopop == 1:把[l,r][l, r][l,r]的所有字符改成c opopop == 2:询问[l,r][l, r][l,r]是否存在长度为c的循环节 解法 首先有一个结论, 若[l,r−c][l, ...

Apale_8的博客 370

【24E】SWT6652 wifi驱动加载失败问题分析及解决方案

修改驱动配置Kconfig。是由于内存分配失败导致。

wgl307293845的博客 219

CODEFORCES 580E Kefa and Watch

題意給出一個字符串,每個字符是 '1' - '9',支持詢問 l, r, d:str[l...r] 是不是以 d 為週期的。並且支持區間修改,將一段的字符都變成某一個。http://codeforces.com/contest/580/problem/E

一直追寻直到哭泣之时 596

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

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

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

Codeforces 580E Kefa and Watch 线段树

参考:http://blog.csdn.net/w703710691d/article/details/48687603 代码: #include #include #include #include #include #include #include #include using namespace std; #define ll long long const ll mod1 =

xiaoyu1_1的专栏 863

WINCC7.3破解文件

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

codeforces 580 E. Kefa and Watch (字符串hash + 线段树)

E. Kefa and Watch time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Kefa the parrot was walking down t

whai的专栏 882

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

【线段树+HASH】CODEFORCES 580E Kefa and Watch

通道 题意:0-9字符串,区间修改,区间询问是否d周期 思路:直接暴力线段树,然后HASH修改和查询,卡HASH的话就双HASH。 代码: #include<cstdio> #include<cstring> typedef long long ll; const int N = 100007; int n, m, k, lens;...

141

字符串hash+线段树 Codeforces580E Kefa and Watch

传送门:点击打开链接 题意:给你一个原串,只有0和9组成。现在有两种操作 操作1,区间修改,把[L,R]的数字都改成d 操作2,询问区间[L,R]中是否满足si = si + x for all i from 1 to |s| - x. 思路:虽然本身会字符串hash,但是没想到还能这样玩。。hash的思路和普通的是一样的,每一位中间乘以某个数字。。如果担心最后的答案,可以对两个大

qwb的博客 1162

Codeforces 580E Kefa and Watch 线段树+双值Hash

传送门:http://codeforces.com/contest/580/problem/E E. Kefa and Watch time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Kefa th

上决╇ф的ACM 1771

codeforces 580 E. Kefa and Watch(hash+线段树)

E. Kefa and Watch time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output One day Kefa the parrot was walking dow

fouzhe的博客 512

线段树 + 字符串Hash - Codeforces 580E Kefa and Watch

Kefa and Watch Problem's Link   Mean:  给你一个长度为n的字符串s,有两种操作: 1 L R C : 把s[l,r]全部变为c; 2 L R d : 询问s[l,r]是否是周期为d的重复串。 analyse: n最大为1e5,且m+k最大也为1e5,这就要求操作1和操作2都要采用lo

北岛知寒 364

CodeForces 580 E.Kefa and Watch(hash+线段树)

Description 给出一个长度为n的数字串s,两种操作: 1 l r c:把s串中区间[l,r]中所有数字都变成c 2 l r d:查询子串[l,r]的是否以d为周期 注:一个串s以d为子串指的是d<=|s|且对任意1<=i<=|s|-d有s[i]=s[i+d] Input 第一行三个整数n,m,k分别表示串长,第一种操作数和第二种操作数,之后一个长度为n的数字串n,最后m+k行每

ZSQ 823

NOIP前咕咕:Codeforces580E. Kefa and Watch

咕咕 转载于:https://www.cnblogs.com/dream-maker-yk/p/9926175.html

weixin_30681121的博客 82

嵌入式软硬件协同:破解‘互相等待’的四大真实卡点

嵌入式系统开发中,硬件与软件的天然耦合与异步节奏构成核心挑战。硬件具有物理不可逆性,依赖制造周期与信号完整性;软件具备逻辑可迭代性,却强依赖真实载体运行。二者在信号可见性、时序约束、BOM参数容忍度及调试基础设施等交界处频繁出现协同断点。这种‘互相等待’并非流程低效,而是物理世界与数字逻辑之间观测尺度、验证方式与责任边界的结构性错位。通过接口契约化、BOM偏差量化、调试就绪标准化等工程实践,可将隐性经验转化为显性资产,实现从被动等待向主动协同跃迁。

weixin_34265814的博客 303
上一篇: codeforces578C. Weakness and Poorness
下一篇: codeforces581F. Zublicanes and Mumocrates
thy_asdf
博客等级 码龄12年 16粉丝 186原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值