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; & ... 
随机推荐
- SpringBoot 2.x (2):请求和传参
			其实请求和传参这些知识属于SpringMVC 不过这也属于必须掌握的知识,巩固基础吧 GET请求: 以第一篇文章自动的方式创建SpringBoot项目: 然后新建Controller: package ... 
- hihocoder offer收割编程练习赛11 B 物品价值
			思路: 状态压缩 + dp. 实现: #include <iostream> #include <cstdio> #include <cstring> #inclu ... 
- Android 使用pl.droidsonroids.gif.GifImageView在安卓中显示动图遇到的问题
			在做一款聊天软件,其中聊天界面需要发送表情,而表情都是动图,在安卓中想要显示动图,就要借助第三方框架,我选的是pl.droidsonroids.gif.GifImageView. 使用方法如下:你在g ... 
- Cannot load php5apache2_4.dll into server     问题的解决方法
			解决方法,重新安装 VC9或 VC11 试试,或者全部安装VC9 VC11 注意:如果下载的 php5.5为32位版本, 那么安装的vc9或VC11 也必须是32位版本. 如果下 ... 
- jboss中JVM监控
			1)打开 http://server-name-or-ip/jmx-console/HtmlAdaptor2)在 jboss.system 节点找到 type=ServerInfo ,点击进入3)找到 ... 
- Nexus环境搭建
			安装 1.解压nexus-2.11.01-bundle.zip到F:\Java\nexus(可自定义) 2.进入F:\Java\nexus\nexus-2.11.1-01\bin\jsw进入相应的系统 ... 
- 360浏览器 收藏夹 ico 缓存 目录
			C:\Users\Administrator\AppData\Roaming\360se6\apps\data\users\default\data\ico 
- CAD参数绘制角度标注(网页版)
			主要用到函数说明: _DMxDrawX::DrawDimAngular 绘制一个角度标注.详细说明如下: 参数 说明 DOUBLE dAngleVertexX 角度标注的顶点的X值 DOUBLE dA ... 
- 使用 reduce 实现数组 map 方法
			//使用 reduce 实现数组 map 方法 const selfMap2 = function (fn, context){ let arr = Array.prototype.slice.cal ... 
- java_线程优先级
			线程优先级分为三个等级: MAX_PIORITY:10 优先 MIN_PRIORITY:1 NORM_PRIORITY:5 默认 getPriority:获取优先级 setPriority:设置优 ... 
