终于补好了。

题目链接: http://codeforces.com/contest/580/problem/E

E. Kefa and Watch
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering by the road. As he came nearer he understood that it was a watch. He decided to take it to the pawnbroker to earn some money.

The pawnbroker said that each watch contains a serial number represented by a string of digits from 0 to 9, and the more quality checks this number passes, the higher is the value of the watch. The check is defined by three positive integers l, r and d. The watches pass a check if a substring of the serial number from l to r has period d. Sometimes the pawnbroker gets distracted and Kefa changes in some substring of the serial number all digits to c in order to increase profit from the watch.

The seller has a lot of things to do to begin with and with Kefa messing about, he gave you a task: to write a program that determines the value of the watch.

Let us remind you that number x is called a period of string s (1 ≤ x ≤ |s|), if si  =  si + x for all i from 1 to |s|  -  x.

Input

The first line of the input contains three positive integers n, m and k (1 ≤ n ≤ 105, 1 ≤ m + k ≤ 105) — the length of the serial number, the number of change made by Kefa and the number of quality checks.

The second line contains a serial number consisting of n digits.

Then m + k lines follow, containing either checks or changes.

The changes are given as 1 l r с (1 ≤ l ≤ r ≤ n, 0 ≤ c ≤ 9). That means that Kefa changed all the digits from the l-th to the r-th to be c.

The checks are given as 2 l r d (1 ≤ l ≤ r ≤ n, 1 ≤ d ≤ r - l + 1).

Output

For each check on a single line print "YES" if the watch passed it, otherwise print "NO".

Sample test(s)
Input
3 1 21122 2 3 11 1 3 82 1 2 1

Output
NOYES

Input
6 2 33349342 2 5 21 4 4 32 1 6 31 2 3 82 3 6 1

Output
NOYESNO

Note

In the first sample test two checks will be made. In the first one substring "12" is checked on whether or not it has period 1, so the answer is "NO". In the second one substring "88", is checked on whether or not it has period 1, and it has this period, so the answer is "YES".

In the second statement test three checks will be made. The first check processes substring "3493", which doesn't have period 2. Before the second check the string looks as "334334", so the answer to it is "YES". And finally, the third check processes substring "8334", which does not have period 1.

大意是:给一个字符串,修改一个区间都为一个值,区间询问区间的两端是否完全相等。

当然HASH啦,但是类似自然溢出会被卡(CF有特殊的卡HASH的技巧,自然溢出就是用unsigned long long 这种,相当于mod 2^64)

这里用双hash,貌似很难很难卡。

HASH1=10^9+9,HASH2=10^9+7

然后就是区间修改,和区间询问,区间修改学的差,看了好久才懂

  1 #include<bits/stdc++.h>
  2 
  3 using namespace std;
  4 
  5 #define N 100005
  6 #define mod1 1000000009
  7 #define mod2 1000000007
  8 
  9 
 10 typedef long long ll;
 11 const int  c1=1997;
 12 const int  c2=1999;
 13 int pow_c1[N],pow_c2[N],sum_c1[N],sum_c2[N];
 14 
 15 struct node{
 16     int l,r;
 17     int h1,h2;
 18     int lazy;
 19     node(){
 20     lazy=-1;
 21     }
 22     void make_lazy(int x)
 23     {
 24         lazy=x;
 25         h1=1ll*sum_c1[r-l]*x%mod1;
 26         h2=1ll*sum_c2[r-l]*x%mod2;
 27     }
 28 }tree[N<<2];
 29 
 30 void lazy_sons(int rt)
 31 {
 32     if (tree[rt].lazy!=-1)
 33     {
 34         tree[rt<<1].make_lazy(tree[rt].lazy);
 35         tree[rt<<1|1].make_lazy(tree[rt].lazy);
 36         tree[rt].lazy=-1;
 37     }
 38 }
 39 
 40 void unite(node &a,node b,node &c){
 41      a.h1=(1ll*b.h1*pow_c1[c.r-c.l+1]%mod1+c.h1)%mod1;
 42      a.h2=(1ll*b.h2*pow_c2[c.r-c.l+1]%mod2+c.h2)%mod2;
 43 }
 44 char s[N];
 45 void build(int l,int r,int rt)
 46 {
 47     tree[rt].l=l,tree[rt].r=r;
 48     tree[rt].lazy=-1;
 49     if (l==r)
 50     {
 51         tree[rt].h1=tree[rt].h2=(s[l]-'0'+1);
 52         return;
 53     }
 54     int mid=(l+r)>>1;
 55     build(l,mid,rt<<1);
 56     build(mid+1,r,rt<<1|1);
 57     unite(tree[rt],tree[rt<<1],tree[rt<<1|1]);
 58 }
 59 void update(int l,int r,int val,int rt)
 60 {
 61     if (tree[rt].l==l&&tree[rt].r==r)
 62     {
 63         tree[rt].make_lazy(val);
 64         return;
 65     }
 66     lazy_sons(rt);
 67     int mid=(tree[rt].l+tree[rt].r)>>1;
 68     if (r<=mid) update(l,r,val,rt<<1);
 69     else if (l>mid) update(l,r,val,rt<<1|1);
 70     else {
 71         update(l,mid,val,rt<<1);
 72         update(mid+1,r,val,rt<<1|1);
 73     }
 74     unite(tree[rt],tree[rt<<1],tree[rt<<1|1]);
 75 }
 76 node ans;
 77 void query(int l,int r,int rt)
 78 {
 79     if (tree[rt].l==l&&tree[rt].r==r){
 80         unite(ans,ans,tree[rt]);
 81         return;
 82     }
 83     lazy_sons(rt);
 84     int mid=(tree[rt].l+tree[rt].r)>>1;
 85     if (r<=mid) query(l,r,rt<<1);
 86     else if (l>mid) query(l,r,rt<<1|1);
 87     else {
 88         query(l,mid,rt<<1);
 89         query(mid+1,r,rt<<1|1);
 90     }
 91 }
 92 int main()
 93 {
 94     pow_c1[0]=sum_c1[0]=1;
 95     pow_c2[0]=sum_c2[0]=1;
 96 
 97     for (int i=1;i<N;i++)
 98     {
 99         pow_c1[i]=1ll*pow_c1[i-1]*c1%mod1;
100         pow_c2[i]=1ll*pow_c2[i-1]*c2%mod2;
101         sum_c1[i]=(1ll*sum_c1[i-1]+pow_c1[i])%mod1;
102         sum_c2[i]=(1ll*sum_c2[i-1]+pow_c2[i])%mod2;
103     }
104     int n,m,k;
105     scanf("%d%d%d",&n,&m,&k);
106 
107     scanf("%s",s+1);
108     build(1,n,1);
109     m+=k;
110     int tp,l,r,c;
111     int aa,bb,cc,dd;
112     while (m--)
113     {
114         scanf("%d%d%d%d",&tp,&l,&r,&c);
115         if (tp==1) update(l,r,c+1,1);
116         else
117         {
118             ans.h1=ans.h2=0;
119             if (l<=r-c) query(l,r-c,1);
120             aa=ans.h1;
121             bb=ans.h2;
122             ans.h1=ans.h2=0;
123             if (l+c<=r) query(l+c,r,1);
124             cc=ans.h1,dd=ans.h2;
125             if (aa==cc&&bb==dd) cout<<"YES"<<endl;
126             else cout<<"NO"<<endl;
127 
128         }
129     }
130     return 0;
131 }

转载于:https://www.cnblogs.com/forgot93/p/4839087.html

Codeforces Round #321 (Div. 2) E相关推荐

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

    原题链接:http://codeforces.com/contest/580/problem/B 题意: 给你一个集合,集合中的每个元素有两个属性,$m_i,s_i$,让你求个子集合,使得集合中的最大 ...

  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) D Kefa and Dishes(dp)

    用spfa,和dp是一样的.转移只和最后一个吃的dish和吃了哪些有关. 把松弛改成变长.因为是DAG,所以一定没环.操作最多有84934656,514ms跑过,实际远远没这么多. 脑补过一下费用流, ...

  5. Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)

    排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...

  6. Codeforces Round #321 (Div. 2)

    水 A - Kefa and First Steps /************************************************ * Author :Running_Time ...

  7. codeforces Round #675 (Div. 2) 1422C Bargain

    题目链接 题目翻译: 有时候想在讲价上达成一致不是一件容易的事.现在Sasha和Vova就没法达成一致:Sasha出了一个尽可能高的价格,然后Vova想要从中去除尽可能多的数字.说得更详细一些,Sas ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

最新文章

  1. 管理距离 路由与交换_动态路由选择原理(距离矢量路由协议RIP)
  2. [Beta]第二次 Scrum Meeting
  3. java生成pdf看不到至值_java生成pdf报错找不到DPF标题签名
  4. 【学习笔记1】CentOS 下载
  5. mysql 时间戳 三天_MySQL格式化时间戳 统计当日,第二天,第三天,3个工作日以后的数据...
  6. 结构体的嵌套 自身嵌套 相互嵌套
  7. CentOS8下安装docker
  8. mybatis学习(25):分页3 多参数传递(使用map)
  9. 语音专题第四讲,语音识别之解码器技术简介|大牛讲堂
  10. HTML上划线 中划线 下划线实现
  11. 如何查计算机硬盘型号,win10电脑的硬盘型号如何查看
  12. 2019 计蒜之道 初赛 第一场 商汤的AI伴游小精灵
  13. 【KSQL引擎 介绍】
  14. Javaweb开发一般步骤
  15. 最详解Docker实例教程
  16. 2022-2028全球与中国药房自动化机器人市场现状及未来发展趋势
  17. ACM省赛及蓝桥总结,且随疾风前行,身后亦须留心
  18. echarts xy轴虚线展示 字体颜色修改
  19. nginx 防止恶意域名解析_nginx防恶意域名解析
  20. grads精致绘图说

热门文章

  1. html5添加到安卓桌面图标,Android向桌面添加快捷方式,使其指向特定的网页
  2. 原始样式增加标题_版式设计!10个技巧让你设计出好的标题
  3. netty web 容器_Netty - 高性能网络应用框架常见面试题
  4. 安卓手机管理器_@你,请查收这款最强的安卓文件管理器
  5. Dubbo-go 源码笔记(一)Server 端开启服务过程
  6. oracle 提取首字母,oracle 取字段文字拼音首字母
  7. csgo陀螺仪是什么意思_CSGO:起源2将在五月中旬推出?B5无意间透露出这个消息...
  8. apt包管理 Android,apt软件包管理学习(示例代码)
  9. mybatis中mysql流式读取_MyBatis读取大量数据(流式读取)
  10. mysql 迭代更新_MySQL、MongoDB、Redis 数据库之间的区别与使用(本章迭代更新)