You have two strings SS and TT in all capitals.

Now an efficient program is required to maintain a operation and support a query.

The operation C~i~chC i ch with given integer ii and capital letter chch, changes the ii-th character of SSinto chch.

The query Q~i~jQ i j asks the program to find out, in the substring of SS from the ii-th character to the jj-th one, the total number of TT appearing.

Input Format

The first line contains an integer TT, indicating that there are TT test cases.

For each test case, the first line contains an integer N~(N \leq 100000)N (N≤100000).

The second line is the string S~(|S| \leq 100000)S (∣S∣≤100000)and the third line is the string T~(|T| \leq 10)T (∣T∣≤10).

Each of the following NN lines provide a operation or a query as above descriptions.

Output Format

For each query, output an integer correponding to the answer.

Output an empty line after each test case.

样例输入

1
5
AABBABA
AA
Q 1 3
C 6 A
Q 2 7
C 2 B
Q 1 5

样例输出

1
2
0
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<functional>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL; const int MAXN = + ;
char s[MAXN];//字符串
bool been[MAXN];//结尾记录是否匹配 匹配为1,不匹配为0
char t[];
int T, n, a[MAXN];
inline int lowbit(int x)
{
return x&(-x);
}
int getsum(int x)
{
if (x == ) return ;
int sum = ;
while (x > )
{
sum += a[x];
x -= x&(-x);
}
return sum;
}
void update(int x, int val)
{
while (x < MAXN)
{
a[x] += val;
x += x&(-x);
}
}
int main()
{
//ios::sync_with_stdio(0);
scanf("%d", &T);
int u, v;
char op[], to[];
while (T--)
{
memset(been, false, sizeof(been));
memset(a, , sizeof(a));
scanf("%d%s%s", &n, s + , t + );
int l = strlen(t + ), L = strlen(s + );
for (int i = ; i + l - <= L; i++)
{
int cnt = ;
while (cnt <= l&&s[i + cnt - ] == t[cnt])cnt++;
if (cnt > l)
{
update(i + l - , );
been[i + l - ] = true;
}
}
//for (int i = 1; i <= L; i++)
// cout << getsum(i) << endl;
while (n--)
{
scanf("%s", op);
if (op[] == 'Q')
{
scanf("%d%d", &u, &v);
printf("%d\n", max(, getsum(v) - getsum(u + l - - )));
}
else if(op[] == 'C')
{
scanf("%d%s", &u, to);
s[u] = to[];
int len = max(, u - l + );
for (int i = len; i <= u; i++)
{
if (i + l - > L) break;
int cnt = ;
while (cnt <= l&&s[i + cnt - ] == t[cnt])cnt++;
if (cnt > l)
{
if (been[i + l - ]) continue;
been[i + l - ] = ;
update(i + l - , );
}
else if (been[i + l - ])
{
been[i + l - ] = ;
update(i + l - , -);
}
}
}
}
cout << endl;
}
}

Query on a string的更多相关文章

  1. KMP的正确使用法_x新疆网络赛Query on a string

    Query on a string 题意,给定一个大字符串,给定一个小模式串,定义 两种不同的任务模式,分别是查询和更改: 查询对应区间内,有多少个匹配到位的数字: 修改某一位的某一个字母. 于是直觉 ...

  2. 【2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 G】Query on a string

    [链接]h在这里写链接 [题意] 让你维护字符串的一段区间内T子串的个数. [题解] 因为t不大,所以. 暴力维护一下a[i]就好. a[i]表示的是S串从i位置开始,能和T串匹配几个字符. 用树状数 ...

  3. how to query for a list<String> in jdbctemplate?--转载

    原文地址:http://stackoverflow.com/questions/13354158/how-to-query-for-a-liststring-in-jdbctemplate   I'm ...

  4. 【Codeforces710F】String Set Queries (强制在线)AC自动机 + 二进制分组

    F. String Set Queries time limit per test:3 seconds memory limit per test:768 megabytes input:standa ...

  5. <<< List<HashMap<String, Object>> 及 HashMap<String, Object> 的用法

    //(赋值)最简单的一种hashMap赋值方式 List<HashMap<String, Object>> aMap= new ArrayList<HashMap< ...

  6. Android:联系人Contacts之ContentResolver query 参数详解

    注:本片整理自 http://blog.csdn.net/wssiqi/article/details/8132603 1.获取联系人姓名 一个简单的例子,这个函数获取设备上所有的联系人ID和联系人N ...

  7. jquery.query.js 插件(示例及简单应用)

    帮助文档 var url = location.search; > "?action=view&section=info&id=123&debug&te ...

  8. lucene query

    在lucene的搜索中,最重要的无疑就是对query的理解和掌握了.这里扒拉一下源码(版本3.5.0)的query和query实现: query是一个抽象类,实现类有以下几个: termQuery m ...

  9. jquery.query.js 插件的用法

    转载自:http://www.cnblogs.com/dachie/archive/2010/09/16/1827840.html 代码如下: var url = location.search; & ...

随机推荐

  1. 构建一个.net的干货类库,以便于快速的开发 - 验证码

    一个验证码对于一个网站的作用不言而喻,而随着技术的发展验证码的种类也开始多了起来,发展至今很多网站已经不再使用一种验证码,为满足需求程序猿就要写很多的方法来适应需求,今天我就来介绍我之前收集到的验证码 ...

  2. 抽象工厂模式和php实现

    抽象工厂模式: 抽象工厂模式(Abstract Factory Pattern):提供一个创建一系列相关或相互依赖对象的接口,而无须指定它们具体的类.抽象工厂模式又称为Kit模式,属于对象创建型模式. ...

  3. C++学习之继承篇

    今天通过对实验二继承,重载,覆盖的学习,让我更深一步理解了这些概念的区别. 首先来明确一个概念,函数名即地址,也就是说函数名就是个指针. 编译阶段,编译器为每个函数的代码分配一个地址空间并编译函数代码 ...

  4. AIX 10G HA RAC卸载

    删除 1:crs_stat –t资源都停掉 2:停ha 3: 删除oracle 4:删除crs 5: 删除ha smit hacmp 6: 删除vg exportvg 7;卸载hacmp smitty

  5. list.extend的结果是None

    执行list.exend()方法后,会直接修改list本身,而不会产生返回值 In [97]: d=(43,) In [98]: type(d) Out[98]: tuple In [99]: c O ...

  6. 输入一个字符串输出ASCII的十六进制值

    #include <stdio.h> #include <string.h> #define LEN 1024 void main() { char s[LEN] = &quo ...

  7. [WDS] Warnings while compiling. vue项目运行控制台输出太多警告信息

    vue项目运行控制台输出太多警告信息,我们需要vue 忽略警告,如Expected indentation of 0 spaces but found 2 这种警告都提示,很影响视觉体验!     解 ...

  8. java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException

    在进行Spring和Hibernate整合的时候遇到了这个问题, 问题描述如下 问题原因?  Spring的Bean的XML配置文件存在错误 解决方法: 正确的配置XML文件,例如下面的代码 < ...

  9. 网络编程 - 协议遇到IO自动切换

    一.协议遇到IO自动切换 python网络编程,遇到IO自动切换,通过模块gevent来实现: import gevent,time def g1(): print ("g1 is star ...

  10. selenium+python自动化unittest之跳过用例skip

    前言 当测试用例写完后,有些模块有改动时候,会影响到部分用例的执行,这个时候我们希望暂时跳过这些用例. 或者前面某个功能运行失败了,后面的几个用例是依赖于这个功能的用例,如果第一步就失败了,后面的用例 ...