【链接】h在这里写链接


【题意】


让你维护字符串的一段区间内T子串的个数。

【题解】


因为t不大,所以。
暴力维护一下a[i]就好。
a[i]表示的是S串从i位置开始,能和T串匹配几个字符。
用树状数组维护区间内a[i]==lent的个数就好。
修改,还是暴力改就行。只会影响到那几个位置的。


【错的次数】


0

【反思】


匹配的部分写在一个函数里面比较好,用起来比较方便。

【代码】

#include <bits/stdc++.h>
using namespace std; const int N = 1e5;
struct BI {
    int a[N + 10];     int lowbit(int x) {
        return x&(-x);
    }     void add(int x, int y) {
        while (x <= N) {
            a[x] += y;
            x += lowbit(x);
        }
    }     int sum(int x) {
        int now = 0;
        while (x > 0) {
            now += a[x];
            x -= lowbit(x);
        }
        return now;
    }     int get_sum(int l, int r) {
        return sum(r) - sum(l - 1);
    } }BIT; char s[N + 20], t[20 + 20];
int Q,a[N+20],lens,lent; void pipei(int pos) {
    a[pos] = 0;
    for (int j = 1; j <= lent && pos + j - 1 <= lens; j++)
        if (s[pos + j - 1] == t[j])
            a[pos] = j;
        else
            break;
} void geta() {
    for (int i = 1; i <= lens; i++) {
        pipei(i);
        if (a[i] == lent) BIT.add(i, 1);
    }
} void in() {
    scanf("%d", &Q);
    scanf("%s%s", s + 1, t + 1);
    lens = strlen(s + 1), lent = strlen(t + 1);
} void cl() {
    for (int i = 1; i <= Q; i++) {
        char r[5];
        scanf("%s", r);
        if (r[0] == 'Q') {
            int a, b;
            scanf("%d%d", &a, &b);
            if (b - lent + 1 < a)
                puts("0");
            else
                printf("%d\n", BIT.get_sum(a,b-lent+1));
        }
        else {
            int pos;
            scanf("%d%s", &pos, r);
            s[pos] = r[0];
            for (int j = max(1,pos - lent + 1); j <= pos; j++) {
                int temp = a[j];
                pipei(j);
                if (temp == lent) {
                    if (a[j] != lent) {
                        BIT.add(j, -1);
                    }
                }
                else
                    if (a[j] == lent)
                        BIT.add(j, 1);
            }
        }
        puts("");
    }
} int main() {
    //freopen("F:\\rush.txt", "r", stdin);
    //ios::sync_with_stdio(0), cin.tie(0);
    int T;
    scanf("%d", &T);
    while (T--) {
        in();
        geta();
        cl();
    }
    return 0;
}

最新文章

  1. WCF服务器证书配置说明-没有能够进行密钥交换的私钥,或者进程可能没有访问私钥的权限
  2. CSS 自定义字体
  3. Java使用ZXing生成二维码条形码
  4. viewpager接受值图片轮播
  5. Java线程池的原理及几类线程池的介绍
  6. 树链剖分(单点更新,求区间最值,区间求和Bzoj1036)
  7. 静态wenb开发,动态web开发
  8. 自己动手写一个简单的(IIS)小型服务器
  9. Lattice Diamond安装
  10. classic asp中使用ADODB.Command防止sql injection
  11. Git简介及安装和简单配置
  12. schedule()函数的调用时机(周期性调度)
  13. qscoj 128 喵哈哈村的魔法源泉(2)(模仿快速幂,好题)
  14. redis 安装实战(10步完成安装)
  15. Python+Selenium基础篇-打开和关闭火狐浏览器
  16. 火车头采集器如何采集QQ群成员中的QQ号
  17. 自学Linux Shell4.1-监测程序ps top kill
  18. C++学习(七)(C语言部分)之 输入
  19. 浅谈 REST 和 RESTFul API
  20. 剑指offer:栈的压入、弹出序列

热门文章

  1. MySQL架构组成之逻辑模块组成
  2. jquery10 闭包示例
  3. c++值传递,指针传递,引用传递以及指针与引用的区别
  4. 配置远程访问阿里云服务器的Redis
  5. 3.索引与string进行映射实现高效查找
  6. Js经典实例收集
  7. javafx drag
  8. 03010_防止SQL注入
  9. Service-监听手机来电
  10. A. Keyboard Codeforces Round #271(div2)