终于补好了。

题目链接: 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 2
112
2 2 3 1
1 1 3 8
2 1 2 1
Output
NO
YES
Input
6 2 3
334934
2 2 5 2
1 4 4 3
2 1 6 3
1 2 3 8
2 3 6 1
Output
NO
YES
NO
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=;
 12 const int  c2=;
 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=-;
 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<<];
 29 
 30 void lazy_sons(int rt)
 31 {
 32     if (tree[rt].lazy!=-)
 33     {
 34         tree[rt<<].make_lazy(tree[rt].lazy);
 35         tree[rt<<|].make_lazy(tree[rt].lazy);
 36         tree[rt].lazy=-;
 37     }
 38 }
 39 
 40 void unite(node &a,node b,node &c){
 41      a.h1=(1ll*b.h1*pow_c1[c.r-c.l+]%mod1+c.h1)%mod1;
 42      a.h2=(1ll*b.h2*pow_c2[c.r-c.l+]%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=-;
 49     if (l==r)
 50     {
 51         tree[rt].h1=tree[rt].h2=(s[l]-''+);
 52         return;
 53     }
 54     int mid=(l+r)>>;
 55     build(l,mid,rt<<);
 56     build(mid+,r,rt<<|);
 57     unite(tree[rt],tree[rt<<],tree[rt<<|]);
 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)>>;
 68     if (r<=mid) update(l,r,val,rt<<);
 69     else if (l>mid) update(l,r,val,rt<<|);
 70     else {
 71         update(l,mid,val,rt<<);
 72         update(mid+,r,val,rt<<|);
 73     }
 74     unite(tree[rt],tree[rt<<],tree[rt<<|]);
 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)>>;
 85     if (r<=mid) query(l,r,rt<<);
 86     else if (l>mid) query(l,r,rt<<|);
 87     else {
 88         query(l,mid,rt<<);
 89         query(mid+,r,rt<<|);
 90     }
 91 }
 92 int main()
 93 {
 94     pow_c1[]=sum_c1[]=;
 95     pow_c2[]=sum_c2[]=;
 96 
 97     for (int i=;i<N;i++)
 98     {
 99         pow_c1[i]=1ll*pow_c1[i-]*c1%mod1;
         pow_c2[i]=1ll*pow_c2[i-]*c2%mod2;
         sum_c1[i]=(1ll*sum_c1[i-]+pow_c1[i])%mod1;
         sum_c2[i]=(1ll*sum_c2[i-]+pow_c2[i])%mod2;
     }
     int n,m,k;
     scanf("%d%d%d",&n,&m,&k);
 
     scanf("%s",s+);
     build(,n,);
     m+=k;
     int tp,l,r,c;
     int aa,bb,cc,dd;
     while (m--)
     {
         scanf("%d%d%d%d",&tp,&l,&r,&c);
         if (tp==) update(l,r,c+,);
         else
         {
             ans.h1=ans.h2=;
             if (l<=r-c) query(l,r-c,);
             aa=ans.h1;
             bb=ans.h2;
             ans.h1=ans.h2=;
             if (l+c<=r) query(l+c,r,);
             cc=ans.h1,dd=ans.h2;
             if (aa==cc&&bb==dd) cout<<"YES"<<endl;
             else cout<<"NO"<<endl;
 
         }
     }
     return ;
 }

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

  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水题100道 第十四题 Codeforces Round #321 (Div. 2) A. Kefa and First Steps (brute force)

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

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

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

  7. 「日常训练」Kefa and Dishes(Codeforces Round #321 Div. 2 D)

    题意与分析(CodeForces 580D) 一个人有\(n\)道菜,然后要点\(m\)道菜,每道菜有一个美味程度:然后给你了很多个关系,表示如果\(x\)刚好在\(y\)前面做的话,他的美味程度就会 ...

  8. 「日常训练」Kefa and Park(Codeforces Round #321 Div. 2 C)

    题意与分析(CodeForces 580C) 给你一棵树,然后每个叶子节点会有一家餐馆:你讨厌猫(waht?怎么会有人讨厌猫),就不会走有连续超过m个节点有猫的路.然后问你最多去几家饭店. 这题我写的 ...

  9. 「日常训练」Kefa and Company(Codeforces Round #321 Div. 2 B)

    题意与分析(CodeForces 580B) \(n\)个人,告诉你\(n\)个人的工资,每个人还有一个权值.现在从这n个人中选出m个人,使得他们的权值之和最大,但是对于选中的人而言,其他被选中的人的 ...

  10. Codeforces Round #321 (Div. 2) Kefa and Dishes 状压+spfa

    原题链接:http://codeforces.com/contest/580/problem/D 题意: 给你一些一个有向图,求不超过m步的情况下,能获得的最大权值和是多少,点不能重复走. 题解: 令 ...

随机推荐

  1. MYSQL 注射精华

    前言鄙人今天心血来潮突然想写篇文章,鄙人从来没写过文章,如果有错误的地方请多多指教.本文需要有基础的SQL语句知识才可以更好的理解.建议想学习的人多去了解一下SQL语句和编程语言,知己知彼才能百战百胜 ...

  2. javase(12)_集合框架_Queue

    一.Queue Queye接口体系图 体系分析: Deque实现类:ArrayDeque, LinkedList(数组和链表实现双向队列) BlockingDeque实现类:LinkedBlockin ...

  3. Linux网卡设置为网桥模式

    Linux网卡设置为网桥模式 1.    添加网卡,并修改相关配置文件 1.1虚拟机添加网卡,并配置相关文件 如:eth2为新添加网卡 cd /etc/sysconfig/network-script ...

  4. 字符串数组 输入3个字符串,要求按由小到大的字母顺序输出; 输入n个学生的姓名和学号到字符串数组中,在输入一个姓名,如果班级有该生则返回其信息,否则返回本班无此人

    输入3个字符串,要求按由小到大的字母顺序输出 如 输入franch england china,输出结果是china england franch 三个数排序输出,比较三个数的大小怎么做? a=18 ...

  5. TortoiseSVN文件夹及文件图标不显示解决方法---20150515

    由于自己的电脑是win7(64位)的,系统安装TortoiseSVN之后,其他的功能都能正常的使用,但是就是文件夹或文件夹的左下角就是不显示图标,这个问题前一段时间就遇到了(那个时候没找到合适的答案) ...

  6. 51nod 1135 原根 (数论)

    题目链接 建议与上一篇欧拉函数介绍结合食用. 知识点:1.阶:a和模m互质,使a^d≡1(mod m)成立的最小正整数d称为a对模m的阶(指数)   例如: 2^2≡1(mod3),2对模3的阶为2; ...

  7. BZOJ4513 SDOI2016 储能表 记忆化搜索(动态规划)

    题意: 题面中文,不予翻译:SDOI2016储能表 分析: 据说有大爷用一些奇怪的方法切掉了这道题%%%%% 这里用的是大众方法——动态规划. 其实这是一道类似于二进制数位dp的动态规划题,(但是实际 ...

  8. Day12装饰器

    1.装饰器 什么是装饰器:装饰器指的是为被装饰对象添加新功能的工具 装饰器本身可以是任意调用对象 被装饰对象本身也可以是任意可调用对象 2.为何要用装饰器: 开放封闭原则: ①对修改源代码和调用方式是 ...

  9. Java并发编程的艺术 记录(一)

    模拟死锁 package com.gjjun.concurrent; /** * 模拟死锁,来源于<Java并发编程的艺术> * @Author gjjun * @Create 2018/ ...

  10. int (*a)[10] 和 int *a[10] 的区别

    int *a[10] :指针数组.数组a里存放的是10个int型指针 int (*a)[10] :数组指针.a是指针,指向一个数组.此数组有10个int型元素 int *a[10] 先找到声明符a,然 ...