用线段树维护哈希,类似于进位制的一个哈希 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的更多相关文章

  1. CF #321 (Div. 2) D

    不说了,爆内存好几次,后来醒起状态有重复... 状压+TSP #include <iostream> #include <cstdio> #include <cstrin ...

  2. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  3. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

  4. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

  5. CF #374 (Div. 2) C. Journey dp

    1.CF #374 (Div. 2)    C.  Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...

  6. CF #371 (Div. 2) C、map标记

    1.CF #371 (Div. 2)   C. Sonya and Queries  map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...

  7. 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) ,问在每个区间里所有 ...

  8. 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 ...

  9. CF#138 div 1 A. Bracket Sequence

    [#138 div 1 A. Bracket Sequence] [原题] A. Bracket Sequence time limit per test 2 seconds memory limit ...

随机推荐

  1. [Swift通天遁地]七、数据与安全-(2)对XML和HTML文档的快速解析

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. 网络简要<入门篇>

    OSI七层 网络的含义:两个不在同一地理位置的主机(终端),通过传输介质和通信协议,实现通信和资源共享. 网络四要素:终端,传输介质 ,通信协议,资源 网络分类: 以范围分类:LAN网(局域网,以太网 ...

  3. JavaScript学习五

    2019-06-02 09:53:42

  4. 巴什博弈------最少取件数 不是1的情况下 hdu---2897

    最少取件数 是1的时候   核心代码是 // 共有 n 见 物品 一次最少取 一个 最多取 m 个 )==) printf("先取者输"); 在代码中  可以看到   题目中 一共 ...

  5. Spring IOC set注入

    Hobby.java package com.wh.bean; public class Hobby { private Integer id; private String name; public ...

  6. azkaban-executor启动时出现conf/global.properties (No such file or directory)的问题解决(图文详解)

     问题详情 // :: INFO [FlowRunnerManager] [Azkaban] Cleaning recently finished // :: INFO [FlowRunnerMana ...

  7. 批量obj格式直接转gltf

    在cesium中的模型需要的是gltf或glb格式的文件,之前的做法是用将模型从3d max中导出dae格式的文件(需要插件),然后用collada2gltf工具将dae格式转成gltf. 最近翻看c ...

  8. .net 程序集加载,版本不匹配的解决方法

    经常有些时候,A.dll引用的是Microsoft.EntityFrameworkCore.dll version=1.0.0.0 publicKeyToken="adb9793829dda ...

  9. todey

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> 框架集fromset ...

  10. 一个ROS的服务,使机器人向前移动指定距离

    源代码有点长,放文末链接里了. 服务描述及代码现在的服务是:请求时携带要前进的距离,然后底盘前进相应距离.代码如下,改动很小: #!/usr/bin/env python import rospyfr ...