CF #321 (Div. 2) E
用线段树维护哈希,类似于进位制的一个哈希 a[i]*p^i+a[i-1]*p^i-1...
然后,线段树存在某区间的哈希的值,对于更新,则只需提前计算出整段的哈希值即可。
判断是否相等,由于相隔为d,只需计算(l+d,r),(l,r-d)两段哈希的值是否相等即可。为了防止一次哈希可能使不符合条件的值哈希值相等,所以进行了两次哈希。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std; const int MAX=100010;
const LL m1=1000000007;
const LL m2=1000000009;
const int g1=47;
const int g2=67; char str[MAX]; struct HASH{
LL seg[MAX<<2]; int lazy[MAX<<2];
LL bits[10][MAX]; LL mod,gt; LL ebit[MAX];
void init(LL m,LL g){
mod=m; gt=g;
for(int i=0;i<MAX;i++){
if(i==0) ebit[i]=1;
else {
ebit[i]=(ebit[i-1]*gt)%mod;
}
}
for(int i=0;i<=9;i++){
bits[i][0]=0;
for(int j=1;j<MAX;j++){
bits[i][j]=(bits[i][j-1]*gt%mod+i)%mod;
}
}
}
void push_up(int rt,int l,int r){
seg[rt]=(seg[rt<<1|1]+seg[rt<<1]*ebit[r-(l+r)/2])%mod;
}
void push_down(int rt,int l,int r){
if(lazy[rt]!=-1){
int m=(l+r)>>1;
lazy[rt<<1]=lazy[rt<<1|1]=lazy[rt];
seg[rt<<1]=bits[lazy[rt]][m-l+1];
seg[rt<<1|1]=bits[lazy[rt]][r-m];
lazy[rt]=-1;
}
}
void build(int rt,int l,int r){
if(l==r){
seg[rt]=(str[l]-'0')%mod;
lazy[rt]=-1;
return ;
}
int m=(l+r)>>1;
build(rt<<1,l,m);
build(rt<<1|1,m+1,r);
push_up(rt,l,r);
lazy[rt]=-1;
}
void update(int rt,int l,int r,int L,int R,int d){
if(l<=L&&R<=r){
lazy[rt]=d;
seg[rt]=bits[d][R-L+1];
return ;
}
int m=(L+R)>>1;
push_down(rt,L,R);
if(m>=l)
update(rt<<1,l,r,L,m,d);
if(m+1<=r)
update(rt<<1|1,l,r,m+1,R,d);
push_up(rt,L,R);
}
void query(int rt ,int l,int r,int L,int R,LL &res){
if(l<=L&&R<=r){
res=(res*ebit[R-L+1]+seg[rt])%mod;
return ;
}
push_down(rt,L,R);
int m=(L+R)>>1;
if(m>=l)
query(rt<<1,l,r,L,m,res);
if(m+1<=r) query(rt<<1|1,l,r,m+1,R,res);
} bool check(int l,int r,int d,int n){
if(r-l+1==d) return true;
LL lrt=0; query(1,l,r-d,1,n,lrt);
LL rrt=0; query(1,l+d,r,1,n,rrt);
if(lrt==rrt) return true;
return false;
}
}a,b; int main(){
// cout<<"OK"<<endl;
int n,m,k,op,l,r,d;
// cout<<"OK"<<endl;
// HASH a,b;
/// cout<<"OK"<<endl;
while(scanf("%d%d%d",&n,&m,&k)!=EOF){
scanf("%s",str+1);
a.init(m1,g1);
b.init(m2,g2);
a.build(1,1,n);
b.build(1,1,n);
/// cout<<"YES"<<endl;
m+=k;
while(m--){
scanf("%d%d%d%d",&op,&l,&r,&d);
if(op==1){
a.update(1,l,r,1,n,d);
b.update(1,l,r,1,n,d);
}
else{
if(a.check(l,r,d,n)&&b.check(l,r,d,n)){
puts("YES");
}
else puts("NO") ;
}
}
}
return 0;
}
CF #321 (Div. 2) E的更多相关文章
- CF #321 (Div. 2) D
不说了,爆内存好几次,后来醒起状态有重复... 状压+TSP #include <iostream> #include <cstdio> #include <cstrin ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
- CF #374 (Div. 2) D. 贪心,优先队列或set
1.CF #374 (Div. 2) D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...
- CF #374 (Div. 2) C. Journey dp
1.CF #374 (Div. 2) C. Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...
- CF #371 (Div. 2) C、map标记
1.CF #371 (Div. 2) C. Sonya and Queries map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...
- CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组
题目链接:CF #365 (Div. 2) D - Mishka and Interesting sum 题意:给出n个数和m个询问,(1 ≤ n, m ≤ 1 000 000) ,问在每个区间里所有 ...
- CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)
转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...
- CF#138 div 1 A. Bracket Sequence
[#138 div 1 A. Bracket Sequence] [原题] A. Bracket Sequence time limit per test 2 seconds memory limit ...
随机推荐
- hadoop一主一从部署(1)
一.安装前说明 主机IP:192.168.132.128 从机IP:192.168.132.129 1. 所有的安装包我放在了/root/这个目录下,你要根据自己情况去修改,这点必须注意 2. 采用的 ...
- jmeter关联、下载文件、简单压测
关联 一.什么是关联 关联是请求与请求之间存在数据依赖关系,需要从上一个请求获取下一个请求需要回传回去的数据. 简单地说就是在测试过程中有些数据的值会经常发生变化,要获取并使用这些数据,把这个动态的信 ...
- [转]java处理高并发高负载类网站的优化方法
本文转自:http://www.cnblogs.com/pengyongjun/p/3406210.html java处理高并发高负载类网站中数据库的设计方法(java教程,java处理大量数据,ja ...
- Laravel5.1学习笔记15 数据库1 数据库使用入门
简介 运行原生SQL查询 监听查询事件 数据库事务 使用多数据库连接 简介 Laravel makes connecting with databases and running queries e ...
- Skeleton Screen — 骨架屏
用户体验一直是前端开发需要考虑的重要部分,在数据请求时常见到锁屏的loading动画,而现在越来越多的产品倾向于使用Skeleton Screen Loading(骨架屏)替代,以优化用户体验. Sk ...
- JS——try catch throw
本例检测输入变量的值.如果值是错误的,会抛出一个异常(错误).catch 会捕捉到这个错误,并显示一段自定义的错误消息: <script> function myFunction() { ...
- VC++ 遍历文件夹
}; strcpy_s(szFind, MAX_PATH, m_szDir); strcat_s(szFind, "\\*.*"); WIN32_FIND_DATA wfd; HA ...
- 12--c完数/最大公约数/最小公倍数/素数/回文数
完数/最大公约数/最小公倍数/素数/回文数 2015-04-08 10:33 296人阅读 评论(0) 收藏 举报 分类: C/C++(60) 哈尔滨工业大学(8) 版权声明:本文为博主原创文章 ...
- 配置本地git服务器(gitblit win7)
title: 配置本地git服务器 date: 2017年3月7日22:43:14 gitblit(不用安装) 进入gitblit-1.8.0\data下,编辑gitblit.properties和d ...
- Lvs Keepalive DR模式高可用配置
Lvs Keepalive DR模式配置 一.环境 #DIP# eth0:192.168.233.145#VIP# eth0:0 192.168.233.250/32 #RIP1:192.168.23 ...