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. 提交应用 Windows Phone的应用程序认证要求

    本文介绍了 Windows Phone 应用程序或游戏要通过认证并在 Windows Phone Marketplace 中发布而必须满足的策略和技术要求. 1.0 计划概述 设计认证过程的一个核心原 ...

  2. struts2 <allowed-methods > 标签配置

    1.在struts2   2.5版本中添加了对方法访问的权限,如果没有被添加到<allow-method> 方法的标签,将会报一下错误 5:05:18.078 [http-apr-8020 ...

  3. 【译】x86程序员手册32-9.4 中断描述符表

    9.4 Interrupt Descriptor Table 中断描述符表 The interrupt descriptor table (IDT) associates each interrupt ...

  4. connection timeout 和command timeout

    每次对数据库连接时,我们有时候会碰到连接超时或者命令超时,这两个超时是不一样的.以ADO.NET为例,当客户端和服务器端连接时,碰到的超时情况主要有下面几种: ''' 当从连接池获取一个连接时,碰到超 ...

  5. K近邻法(K-Nearest Neighbor,KNN)

    KNN是一种基本分类与回归方法,本篇只总结分类问题中的KNN. 输入:样本的特征向量,对应于特征空间中的点 输出:样本的类别,可取多类 算法思想:给定一个样本类别已知的训练数据集,对于新样本,根据其K ...

  6. HDU_1237_简单计算器

    运算符为+,-,*,/:操作数为整数:且没有括号 设定符号优先级,先在栈底压运算符0 #include<iostream> #include<cstdio> #include& ...

  7. CREATE VIEW - 定义一个视图

    SYNOPSIS CREATE [ OR REPLACE ] VIEW name [ ( column_name [, ...] ) ] AS query DESCRIPTION 描述 CREATE ...

  8. 不能局部安装webpack的解决方法

    npm ERR! code ENOSELFnpm ERR! Refusing to install package with name "webpack" under a pack ...

  9. VS2008 ActiveX(ocx控件)的调试工具ActiveX Control Test Container安装说明

    vs2008中的TSTCON( ActiveX Control Test Container )工具非自动安装,而是作为一个例程提供.所以应找到该例程,并编译: 如vs2008安装在默认路径则 1, ...

  10. 单文件组件.vue---父子组件通信

    每一个.vue 文件就是一个 组件,组件和组件相互组合,就成了一个应用,这就涉及到的组件和组件之间的通信,最常用的就是父子之间的通信.在vue 中, 在一个组件中通过 import 引入另一个组件,这 ...