Codeforces Round #321 (Div. 2) E - Kefa and Watch
题目大意:给你一个由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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #321 (Div. 2) D. Kefa and Dishes(状压dp)
http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Mybatis 学习总结
1 Mybatis入门 1.1 单独使用jdbc编程问题总结 1.1.1 jdbc程序 public static void main(String[] args) { Connection conn ...
- Java基础其他
1. 二进制 进制就是进位制,常见的有二进制.十进制.十六进制等 在进制中,可用符号的数量称为基数,基数为n就称为n进制,逢n进一位: 二进制:0 1 十进制:0 1 2 3 4 5 6 7 8 9 ...
- Win Server 2008 R2 IIS 默认只能添加一个 443 HTTPS 端口
问题: 解决方案: 方法一: 然后在:C:\Windows\system32\inetsrv\config\applicationHost.config 找到 对应网站 <binding pro ...
- Elastic Job入门(1) - 简介
介绍 构建一般的业务系统来说,使用Quartz或者Spring Task即可基本满足我们的单体服用应用需要.然而随着线上业务量的不断发展,这两种定时任务已经日渐无法满足我们的需求.一般,使用这两种定时 ...
- CF1009F Dominant Indices
传送门 还是放个链接让泥萌去学一下把 orzYYB 题目中要求的\(f_{x,j}\),转移是\(f_{x,j}=\sum_{y=son_x} f_{y,j-1}\),所以这个东西可以用长链剖分优化, ...
- SpringBootTest单元测试实战、SpringBoot测试进阶高级篇之MockMvc讲解
1.@SpringBootTest单元测试实战 简介:讲解SpringBoot的单元测试 1.引入相关依赖 <!--springboot程序测试依赖,如果是自动创建项目默认添加--> &l ...
- IOS中的三大事件
iOS 中,所有显示在界面上的对象都是从 UIResponder 直接或间接继承的,只有继承了它才可以处理事件.而在ios中的事件可以分为三大类: 1.触摸事件 2.加速计事件(摇一摇) 3.远程控制 ...
- Android五种数据存储方式
android 五种数据存储 :SharePreferences.SQLite.Contert Provider.File.网络存储 Android系统提供了四种存储数据方式.分别为:SharePre ...
- oaracel 函数_行转列
wm_concat(varchar2) 组函数
- WPF当中StaticResource调用方法
1.先在Converter命名空间当中,定义转换功能类: public sealed class BoolToValueConverter : System.Windows.Data.IValueCo ...