Query on a string
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的更多相关文章
- KMP的正确使用法_x新疆网络赛Query on a string
Query on a string 题意,给定一个大字符串,给定一个小模式串,定义 两种不同的任务模式,分别是查询和更改: 查询对应区间内,有多少个匹配到位的数字: 修改某一位的某一个字母. 于是直觉 ...
- 【2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 G】Query on a string
[链接]h在这里写链接 [题意] 让你维护字符串的一段区间内T子串的个数. [题解] 因为t不大,所以. 暴力维护一下a[i]就好. a[i]表示的是S串从i位置开始,能和T串匹配几个字符. 用树状数 ...
- how to query for a list<String> in jdbctemplate?--转载
原文地址:http://stackoverflow.com/questions/13354158/how-to-query-for-a-liststring-in-jdbctemplate I'm ...
- 【Codeforces710F】String Set Queries (强制在线)AC自动机 + 二进制分组
F. String Set Queries time limit per test:3 seconds memory limit per test:768 megabytes input:standa ...
- <<< List<HashMap<String, Object>> 及 HashMap<String, Object> 的用法
//(赋值)最简单的一种hashMap赋值方式 List<HashMap<String, Object>> aMap= new ArrayList<HashMap< ...
- Android:联系人Contacts之ContentResolver query 参数详解
注:本片整理自 http://blog.csdn.net/wssiqi/article/details/8132603 1.获取联系人姓名 一个简单的例子,这个函数获取设备上所有的联系人ID和联系人N ...
- jquery.query.js 插件(示例及简单应用)
帮助文档 var url = location.search; > "?action=view§ion=info&id=123&debug&te ...
- lucene query
在lucene的搜索中,最重要的无疑就是对query的理解和掌握了.这里扒拉一下源码(版本3.5.0)的query和query实现: query是一个抽象类,实现类有以下几个: termQuery m ...
- jquery.query.js 插件的用法
转载自:http://www.cnblogs.com/dachie/archive/2010/09/16/1827840.html 代码如下: var url = location.search; & ...
随机推荐
- 初学者对C++的切身感受
上周和一同学聊起了当前一些比较流行且运用广范的编程语言,苹果的IOS比起其它语言 来说更加言简意赅,简单明了,并且他现在也打算一直弄IOS.我之前一直是用C语言和 GNU ARM汇编语言,因为这两种语 ...
- day21-4 菱形继承问题(类的查找顺序)
目录 菱形继承问题 经典类(了解) 新式类 mro方法 菱形继承问题 在Python中子类可以同时继承多个父类,如A(B,C,D) 如果继承关系为非菱形结构,则会按照先找B这一条分支,然后再找C这条分 ...
- ar - 建立, 修改档案或从档案中抽取成员.
总览 ar [-]{dmpqrtx}[abcfilNoPsSuvV] [membername] [count] archive files... 描述 GNU 组织的ar 程序 用于建立, 修改档案 ...
- jQuery动态移除和绑定事件
function bindEvent() { //移除绑定事件 $('.btnsp').unbind('click'); //绑定事件 $('.btnsp').bind('click', functi ...
- 11-2 numpy/pandas/matplotlib模块
目录 numpy模块 一维数组 二维数组 列表list和numpy的区别 获取多维数组的行和列 多维数组的索引 高级功能 多维数组的合并 通过函数方法创建多维数组 矩阵的运算 求最大值最小值 nump ...
- 第1节 MapReduce入门:11、mapreduce程序的入门
1.1.理解MapReduce思想 MapReduce思想在生活中处处可见.或多或少都曾接触过这种思想.MapReduce的思想核心是“分而治之”,适用于大量复杂的任务处理场景(大规模数据处理场景). ...
- 样例GeoQuiz应用开发 第2章
先介绍一下MVC,Model View Controller,是软件架构中最常见的一种框架. 简单来说就是通过 controller 的控制去操作 model 层的数据,并且返回给 view 层展示, ...
- SDOI2015约数个数和
题目描述 题解: 有一个式子: 证明先不说了. 然后倒一波反演: 然后整除分块就好了. 代码: #include<cstdio> #include<cstring> #incl ...
- 零基础入门学习Python(23)--递归:这帮小兔崽子
知识点 我们都知道兔子繁殖能力是惊人的,如下图: 我们可以用数学函数来定义: 假设我们需要求出经历了20个月后,总共有多少对小兔崽子? 迭代实现 def fab(n): n1 = 1 n2 = 1 n ...
- 关于ie8下disabled属性:字体颜色问题
在ie8下,input/textarea输入框如果使用disabled属性,字体的颜色会变灰,这时我们可以使用另一种方法实现它. 不使用disabled,用readonly代替: input[read ...