zoukankan      html  css  js  c++  java
  • CF914F Substrings in a String bitset的应用 Shift -And

    给你一个字符串s,共有q次操作,每个都是下面两种形式的一种。

    • 1 i c:这个操作表示将字符串s的第i项变为字符c
    • 2 l r y:这个操作表示输出字符串y在字符串s中以第l项为起点,以第r项为终点的子串(包括第l和第r项)中作为子串出现的次数。

     考虑到有修改操作,跑KMP必然是不行的。

    因此考虑暴力操作 + biset 维护,|y| 和最大是1e5 ,由于题给6秒,因此可以考虑 bitset

    ans的某位位1代表这一位存在子串,所以最后count一下1的个数就好。

    #pragma warning(disable:4996)
     
    #include<iostream>
    #include<algorithm>
    #include<bitset>
    #include<tuple>
    #include<unordered_map>
    #include<fstream>
    #include<iomanip>
    #include<string>
    #include<cmath>
    #include<cstring>
    #include<vector>
    #include<map>
    #include<set>
    #include<list>
    #include<queue>
    #include<stack>
    #include<sstream>
    #include<cstdio>
    #include<ctime>
    #include<cstdlib>
    #define INF 0x3f3f3f3f
    #define inf 0x7FFFFFFF
    #define MOD 998244353
    #define moD 1000000003
    #define pii pair<int,string>
    #define eps 1e-8
    #define equals(a,b) (fabs(a-b)<eps)
    #define bug puts("bug")
    #define re  register
    #define fi first
    #define se second
    const int maxn = 1e5 + 5;
    const double Inf = 10000.0;
    const double PI = acos(-1.0);
    typedef  long long ll;
    typedef unsigned long long ull;
    using namespace std;
     
    char s[maxn], ss[maxn];
    bitset<maxn> v[26];
    bitset<maxn> ans;
     
    int main() {
        int q;
        int x, y, l, r;
        scanf("%s", s + 1);
        int len = strlen(s + 1);
        for (int i = 1; i <= len; i++) {
            v[s[i] - 'a'][i] = 1;
        }
        scanf("%d", &q);
        while (q--) {
            scanf("%d", &x);
            if (x == 1) {
                char ch;
                scanf("%d %c", &y, &ch);
                v[s[y] - 'a'][y] = 0;
                v[(s[y]= ch) - 'a'][y] = 1;
            }
            else {
                scanf("%d%d", &l, &r);
                scanf("%s", ss);
                int length = strlen(ss);
                if (r - l + 1 < length) {
                    puts("0");
                    continue;
                }
                ans.set();
                for (int j = 0; j < length; j++) ans &= (v[ss[j] - 'a'] >> j);
                printf("%d
    ", (int)(ans >> l).count() - (int)(ans >> (r - length + 2)).count());
            }
        }
    }
  • 相关阅读:
    New Skateboard
    1127
    一张图看懂开源许可协议,开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别
    vim 快捷键绑定
    使用git 上传项目到gitee/github
    Linux进程/线程调度策略与 进程优先级
    【框架】共享内存组设计思路与实现(更新中)
    linux下六大IPC机制【转】
    详解Linux内核红黑树算法的实现
    Linux 内核里的数据结构:红黑树(rb-tree)
  • 原文地址:https://www.cnblogs.com/hznumqf/p/13307519.html
Copyright © 2011-2022 走看看