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 ...
随机推荐
- Android studio 自动导入(全部)包 import
http://blog.csdn.net/buaaroid/article/details/44979629 1 Android studio 只有import单个包的快捷键:Alt+Enter.没有 ...
- 夏令时(DST)测试
夏令时测试是比较小众的测试,主要针对在有夏令时的国家使用的软件,如果你接触到了这方面的测试,说明你在挣国外的钱:). 话不多说,先来介绍下什么是夏令时: 夏时制,夏时令(Daylight Sa ...
- scapy的安装
我是安装了sulley,这里安装了pcapy的模块. https://github.com/zlorb/scapy ----按照此链接的步骤安装 但是在安装pycrypto模块出现了错误. 这里通 ...
- POJ1113 Wall【凸包】
题意: 求把城堡围起来需要的最小墙壁周长. 思路: 围墙周长为=n条平行于凸包的线段+n条圆弧的长度=凸包周长+围墙离城堡距离L为半径的圆周长. 代码: ...还是看大佬写的,自己做个记录方便日后复习 ...
- linux C sscanf()函数
linux sscanf() 类似正则表达式,又不完全是正则表达式. 分割 ”/“ 或 "@" 或空格 要用 [^/] 例如: sscanf("iios/12DDWDFF ...
- windws 下 sublime Text 3 ·安装的安装与激活
下载sublime 我们可以到官网进行下载对应的版本 https://www.sublimetext.com/3 如下是官网的内容(我选择的是Windows 64 bit). Sublime Text ...
- C++11模板友元语法
第 1 类: 普通类A的 普通类B 友元(一对一友好关系): 无需前置声明class B,当class B第一次出现在friend声明中时,该名字被隐式地认为可见. class A { friend ...
- 批量下载Coursera及其他场景上的文件
以下方法同样适用于其他场景的批量下载. 最近在学习Coursera退出的深度学习课程,我希望把课程提供的作业下载下来以备以后复习,但是课程有很多文件,比如说脸部识别一课中的参数就多达226个csv文件 ...
- IDEA常用快捷键[转]
原文:http://www.cnblogs.com/wxdlut/p/3410541.html 查询快捷键CTRL+N 查找类CTRL+SHIFT+N 查找文件CTRL+SHIFT+ALT+N ...
- freeRTOS中文实用教程6--错误排查
1.前言 本章主要是为刚接触FreeRTOS 的用户指出那些新手通常容易遇到的问题.这里把最主要的篇幅放在栈溢出以及栈溢出侦测上 2.printf-stdarg.c 当调用标准C 库函数时,栈空间使用 ...