题目大意:给你一个由0-9组成的字符串,有m个询问,两种操作,第一种将l到r的字符全部变成c,第二种问l到r这段

字符串的循环节是不是d。

思路:首先我们要知道怎么判断字符串的循环节的长度是不是d,如果这个字符串小于等于d,那么肯定是的,否则,如果l 到 r-d

和l+d 到 r 这两段字符串则循环节的长度是d,反之不是。 然后我们就用线段树维护区间字符串哈希值就好啦。

#include<bits/stdc++.h>
#define read(x) scanf("%d",&x)
#define lread(x) scanf("%lld",&x)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mk make_pair
using namespace std; typedef long long ll;
const int N=1e5+;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int mod=;
const int base=; int n,m,k;
ll b[N],sum[N]; struct seg_tree
{
struct node
{
ll hs;
int l,r,lazy;
}a[N<<];
void up(int l,int r,int rt)
{
int mid=(l+r)>>;
int len=r-mid;
a[rt].hs=(a[rt<<].hs*b[len]+a[rt<<|].hs)%mod;
}
void down(int l,int r,int rt)
{
if(a[rt].lazy==-) return;
int c=a[rt].lazy; a[rt].lazy=-;
a[rt<<].lazy=a[rt<<|].lazy=c;
int mid=(l+r)>>;
a[rt<<].hs=c*sum[mid-l]%mod;
a[rt<<|].hs=c*sum[r-mid-]%mod;
}
void build(int l,int r,int rt)
{
a[rt].l=l; a[rt].r=r;
a[rt].lazy=-;
if(l==r)
{
int x; scanf("%1d",&x);
a[rt].hs=x;
return;
}
int mid=(l+r)>>;
build(l,mid,rt<<);
build(mid+,r,rt<<|);
up(l,r,rt);
}
void updata(int L,int R,int c,int rt)
{
int l=a[rt].l,r=a[rt].r;
if(l>=L && r<=R)
{
a[rt].lazy=c;
a[rt].hs=c*(sum[r-l])%mod;
return;
}
down(l,r,rt);
int mid=(l+r)>>;
if(L<=mid) updata(L,R,c,rt<<);
if(R>mid) updata(L,R,c,rt<<|);
up(l,r,rt);
}
ll query(int L,int R,int rt)
{
int l=a[rt].l,r=a[rt].r;
if(l>=L && r<=R)
return a[rt].hs;
down(l,r,rt);
int mid=(l+r)>>;
ll ans=;
int len=max(,min(R,r)-mid);
if(R>mid) ans=query(L,R,rt<<|);
if(L<=mid) ans=(ans+query(L,R,rt<<)*b[len])%mod;
return ans;
}
}seg;
bool check(int l,int r,int d)
{
if(r-l+<=d)
return true;
ll hs1=seg.query(l,r-d,);
ll hs2=seg.query(l+d,r,);
return hs1==hs2;
}
void init()
{
b[]=; sum[]=;
for(int i=;i<N;i++)
b[i]=b[i-]*base%mod;
for(int i=;i<N;i++)
sum[i]=(sum[i-]+b[i])%mod;
}
int main()
{
init();
read(n); read(m); read(k);
seg.build(,n,);
for(int i=;i<=m+k;i++)
{
int op,l,r;
read(op);
read(l); read(r);
if(op==)
{
int c; read(c);
seg.updata(l,r,c,);
}
else
{
int d; read(d);
if(check(l,r,d))
puts("YES");
else
puts("NO");
}
}
return ;
}

Codeforces Round #321 (Div. 2) E - Kefa and Watch的更多相关文章

  1. Codeforces Round #321 (Div. 2) E. Kefa and Watch 线段树hash

    E. Kefa and Watch Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/prob ...

  2. Codeforces Round #321 (Div. 2) C. Kefa and Park dfs

    C. Kefa and Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/probl ...

  3. Codeforces Round #321 (Div. 2) B. Kefa and Company 二分

    B. Kefa and Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/pr ...

  4. Codeforces Round #321 (Div. 2) A. Kefa and First Steps 水题

    A. Kefa and First Steps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/58 ...

  5. Codeforces Round #321 (Div. 2) D. Kefa and Dishes 状压dp

    题目链接: 题目 D. Kefa and Dishes time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 W ...

  6. codeforces水题100道 第十四题 Codeforces Round #321 (Div. 2) A. Kefa and First Steps (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/580/A题意:求最长连续非降子序列的长度.C++代码: #include <iostream ...

  7. Codeforces Round #321 (Div. 2) D. Kefa and Dishes(状压dp)

    http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有 ...

  8. Codeforces Round #321 (Div. 2) A. Kefa and First Steps【暴力/dp/最长不递减子序列】

    A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  9. Codeforces Round #321 (Div. 2) E Kefa and Watch (线段树维护Hash)

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

  10. Codeforces Round #321 (Div. 2)-A. Kefa and First Steps,暴力水过~~

    A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. linux系统--磁盘管理命令(一)

    一.基本命令 1.1 查看磁盘分区使用状况:df 参数: l:仅显示本地磁盘(默认) a:显示所有文件系统的磁盘使用情况,包括比如 /proc/ h:以1024进制计算最合适的单位显示磁盘容量 H:以 ...

  2. u-boot移植(十三)---代码修改---裁剪及环境变量 二

    一.错误处理 上一节遇到一个错误: print一下: 发现我们在jz2440.h中静态写的网络参数都没有写进去. dm9000 address not set. dm9000的地址未设置. 这里对应两 ...

  3. luogu 1631 序列合并

    priority_queue的使用,注意 a[1]+b[1],a[1]+b[2],a[1]+b[3],a[1]+b[4].......a[1]+b[n] a[2]+b[1]......... .. a ...

  4. 51nod1331 狭窄的通道

    题目传送门 这道题 51nod只Ac了十二个人 没有题解可以研究 所以就自己YY了半天 在这里先感谢一波岚清大爷 orz 然后这道题我分了两种情况 一种是左边的往左跑右边的往右跑 中间有一部分直接走不 ...

  5. C# HTTP上传多个文件及传递参数

    1.HTTP上传文件及传递参数 #region 6.0 上传多个文件和参数 /// <summary> /// HttpUploadFile /// </summary> // ...

  6. python(七) Python中单下划线和双下划线

    Python中单下划线和双下划线: 一.分类 (1).以单下划线开头,表示这是一个保护成员,只有类对象和子类对象自己能访问到这些变量. 以单下划线开头的变量和函数被默认是内部函数,使用from mod ...

  7. More Effective C++ 条款0,1

    More Effective C++ 条款0,1 条款0 关于编译器 不同的编译器支持C++的特性能力不同.有些编译器不支持bool类型,此时可用 enum bool{false, true};枚举类 ...

  8. ubuntu14.04 安装Kdevelop 进行ROS开发

    1. 安装gcc sudo apt-get build-dep gcc sudo apt-get install build-essential  2. 安装Kdevelop sudo apt-get ...

  9. /etc/profile 路径出错后相关的命令失效解决方式

    关于 Linux 的配置文件 /etc/profile 路径出错后相关的命令失效解决方式(如:ls,vi不能用) 今天学习LINUX 下配置jdk 和安装tomcat 通过VI编辑/etc/profi ...

  10. find结合rm删除或mv移动文件的方法

    删除过期的备份文件,多用find结合rm方法,可以使用-exec或xargs -exec rm -rf {} \; 或 find /home/mysqlbackup -name "*$thi ...