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. bootstrap不同屏幕区分数值

    @media (min-width:1200px){ } @media (min-width:992px) and (max-width:1199px){ } @media (min-width:76 ...

  2. iOS programming UITabBarController

    iOS programming UITabBarController 1.1 View controllers become more interesting when the user's acti ...

  3. iOS - 事件处理全过程(补充)

    事件处理的完整过程 1> 先将事件对象由上往下传递(由父控件传递给子控件),找到最合适的控件来处理这个事件. 2> 调用最合适控件的touches….方法 3> 如果调用了[supe ...

  4. Request.Form("id")与Request.QueryString("id")的区别

    获取以表单提交的post类型的值,也就是获取<form method="post">这种方式提交的值request包含各种方式的值,没有指名是什麽,所以Request. ...

  5. ECharts Map 属性详解

    $(function() { // 路径配置 require.config({ paths : { // echarts: 'http://echarts.baidu.com/build/dist' ...

  6. Farseer.net轻量级ORM开源框架 V1.x 入门篇:存储过程数据操作

    导航 目   录:Farseer.net轻量级ORM开源框架 目录 上一篇:Farseer.net轻量级ORM开源框架 V1.x 入门篇:存储过程实体类映射 下一篇:Farseer.net轻量级ORM ...

  7. 迅为电子iTOP-HMI043 4.3寸人机界面产品

    4.3寸人机界面: 7寸人机界面: 10.2寸人机界面: 产品认证CE:符合EN61000-6-2:2005, EN61000-6-4:2007标准FCC 兼容性:符合FCC Class A面板防护等 ...

  8. Java Web数据库篇之MySQL特性

    MySQL ExplainEXPLAIN 命令的输出内容大致如下: mysql> explain select * from user_info where id = 2\G********** ...

  9. Java方法注释模板

    普通方法 /** * ${todo} * @author: SYJP * @version 创建时间:${date} */ 覆盖方法 /** * @Title: ${enclosing_method} ...

  10. yum升级php版本

    查看当前 PHP 版本 1 php -v 查看当前 PHP 相关的安装包,删除之 1 2 3 4 5 yum list installed | grep php   yum remove php   ...