Problem Description
You are given two strings s1[0..l1], s2[0..l2] and Q - number of queries.

Your task is to answer next queries:

  1) 1 a i c - you should set i-th character in a-th string to c;

  2) 2 i - you should output the greatest j such that for all k (i<=k and k<i+j) s1[k] equals s2[k].
 

Input
The first line contains T - number of test cases (T<=25).

Next T blocks contain each test.

The first line of test contains s1.

The second line of test contains s2.

The third line of test contains Q.

Next Q lines of test contain each query:

  1) 1 a i c (a is 1 or 2, 0<=i, i<length of a-th string, 'a'<=c, c<='z')

  2) 2 i (0<=i, i<l1, i<l2)

All characters in strings are from 'a'..'z' (lowercase latin letters).

Q <= 100000.

l1, l2 <= 1000000.
 

Output
For each test output "Case t:" in a single line, where t is number of test (numbered from 1 to T).

Then for each query "2 i" output in single line one integer j.
 

Sample Input

1
aaabba
aabbaa
7
2 0
2 1
2 2
2 3
1 1 2 b
2 0
2 3
 

Sample Output

Case 1:
2
1
0
1
4
1

这题属于区间合并,维护线段的llen(线段从左端点开始向右的最长连续1的长度),rlen(线段从右端点开始向左的最长连续1的长度),tlen(线段中最长连续1的长度,记录这个主要是为了剪枝,减少时间)。一开始先初始化,两个字符串,相同的部分记为1,不同的记为0,注意两个字符串的长度可能不同。

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define maxn 1000100
char s1[maxn],s2[maxn];
int a[maxn],num;
struct node{
int l,r,llen,rlen,tlen;
}b[4*maxn]; void pushup(int i)
{
b[i].tlen=max(b[i*2].tlen,b[i*2+1].tlen);
b[i].tlen=max(b[i].tlen,b[i*2].rlen+b[i*2+1].llen); b[i].llen=b[i*2].llen;b[i].rlen=b[i*2+1].rlen;
if(b[i*2].llen==b[i*2].r-b[i*2].l+1)b[i].llen+=b[i*2+1].llen;
if(b[i*2+1].rlen==b[i*2+1].r-b[i*2+1].l+1)b[i].rlen+=b[i*2].rlen;
} void build(int l,int r,int i)
{
int mid;
b[i].l=l;b[i].r=r;
if(l==r){
b[i].tlen=b[i].llen=b[i].rlen=a[l];return;
}
mid=(l+r)/2;
build(l,mid,i*2);
build(mid+1,r,i*2+1);
pushup(i);
} void update(int id,int value,int i)
{
int mid;
if(b[i].l==b[i].r){
b[i].tlen=b[i].llen=b[i].rlen=value;return;
}
mid=(b[i].l+b[i].r)/2;
if(mid>=id)update(id,value,i*2);
else update(id,value,i*2+1);
pushup(i);
} void question(int id,int i)
{
int mid;
if(b[i].l==b[i].r){
num=1;return;
}
if(b[i].tlen==b[i].r-b[i].l+1){
num=b[i].r-id+1;return;
}
mid=(b[i].l+b[i].r)/2;
if(mid>=id){ //用4个剪枝试一试
if(b[i*2].r-b[i*2].rlen+1<=id){
num=b[i*2].r-id+1+b[i*2+1].llen;return;
}
else{
question(id,i*2);
}
}
else{
if(b[i*2+1].l+b[i*2+1].llen-1>=id){
num=b[i*2+1].l+b[i*2+1].llen-1-id+1;return;
}
else question(id,i*2+1);
}
} int main()
{
int n,m,i,j,T,len1,len2,len,d,e,flag,c,num1=0;
char f[10];
scanf("%d",&T);
while(T--)
{
num1++;
printf("Case %d:\n",num1);
scanf("%s%s",s1+1,s2+1);
len1=strlen(s1+1);len2=strlen(s2+1);
len=min(len1,len2);
for(i=1;i<=len;i++){
if(s1[i]==s2[i])a[i]=1;
else a[i]=0;
}
build(1,len,1);
scanf("%d",&m);
for(i=1;i<=m;i++){
scanf("%d",&c);
if(c==1){
scanf("%d%d%s",&d,&e,f);
e++;
if(e>len)continue;
if(s1[e]==s2[e])flag=1;
else flag=0; if(d==1)s1[e]=f[0];
else s2[e]=f[0];
if(s1[e]==s2[e] && flag==0)update(e,1,1);
else if(s1[e]!=s2[e] && flag==1)update(e,0,1); //这里可以节省200ms
}
else if(c==2){
scanf("%d",&d);
d++;
if(d>len || s1[d]!=s2[d]){
printf("0\n");continue;
}
num=0;
question(d,1);
printf("%d\n",num);
}
}
}
}

hdu4339 Query的更多相关文章

  1. 以bank account 数据为例,认识elasticsearch query 和 filter

    Elasticsearch 查询语言(Query DSL)认识(一) 一.基本认识 查询子句的行为取决于 query context filter context 也就是执行的是查询(query)还是 ...

  2. 相关query挖掘

    1.何为相关query 我通常也把相关query称为相似query,搜索日志中一个用户在短时间内的一系列搜索词被称为相关query.相关就是两个query间有一定的关系,反映了用户在当时的需求.本文就 ...

  3. 第三篇 Entity Framework Plus 之 Query Cache

    离上一篇博客,快一周,工作太忙,只能利用休息日来写一些跟大家分享,Entity Framework Plus 组件系列文章,之前已经写过两篇 第一篇 Entity Framework Plus 之 A ...

  4. 第二篇 Entity Framework Plus 之 Query Future

    从性能的角度出发,能够减少 增,删,改,查,跟数据库打交道次数,肯定是对性能会有所提升的(这里单纯是数据库部分). 今天主要怎样减少Entity Framework查询跟数据库打交道的次数,来提高查询 ...

  5. FunDA(1)- Query Result Row:强类型Query结果行

    FunDA的特点之一是以数据流方式提供逐行数据操作支持.这项功能解决了FRM如Slick数据操作以SQL批次模式为主所产生的问题.为了实现安全高效的数据行操作,我们必须把FRM产生的Query结果集转 ...

  6. 细谈Slick(6)- Projection:ProvenShape,强类型的Query结果类型

    在Slick官方文档中描述:连接后台数据库后,需要通过定义Projection,即def * 来进行具体库表列column的选择和排序.通过Projection我们可以选择库表中部分列.也可以增加一些 ...

  7. elasticsearch__5__java操作之FilterBuilders构建过滤器Query

    FilterBuilders构建过滤器Query 代码如下: package com.elasticsearch; import org.elasticsearch.action.ActionList ...

  8. [LeetCode] Range Sum Query 2D - Mutable 二维区域和检索 - 可变

    Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...

  9. [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

随机推荐

  1. jenkins 构建历史 显示版本号

    0   jenkins 安装此插件: 此插件名为 " groovy postbuild " 1  效果图: 2   安装插件: 系统管理 --> 插件管理 --> 可选 ...

  2. ubuntu 上搭建 go的开发环境 vscode

    原文链接: https://astaxie.gitbooks.io/build-web-application-with-golang/zh/01.4.html 原本我是在windows下进行go的环 ...

  3. Loadrunner与kylinPET的能力对比测试--web动态请求

    概述 在<性能测试工具选择策略--仿真度对比测评分析报告>一文详细分析了使用相同的web页面,分别使用LoadRunner,Jmeter,kylinTOP工具进行录制脚本并执行得出在静态请 ...

  4. 【高级排序算法】2、归并排序法的实现-Merge Sort

    简单记录 - bobo老师的玩转算法系列–玩转算法 -高级排序算法 Merge Sort 归并排序 Java实现归并排序 SortTestHelper 排序测试辅助类 package algo; im ...

  5. 【Oracle】想查询相关的v$视图,但是提示表或视图不存在解决办法

    原因是使用的用户没有相关的查询权限导致 解决办法: grant select  any dictionary to 用户;    --这个权限比较大 这个权限是最低的要求,但是可以访问到v$相关视图 ...

  6. fileinput模块用法

    fileinput模块功能: 提供拼接一个或多个文本文件的功能,可以通过使用for循环来读取一个或多个文本文件的所有行,从而进行逐行处理(如进行显示.替换.添加行号等). 其功能类似于linux命令的 ...

  7. 2.4V升3.3V,2.4V升3V,1A大电流升压芯片

    两节镍氢电池串联就是1.2V+1.2V=2.4V的供电电压了,2.4V升3V, 2.4V升3.3V的话,就能稳压稳定给模块供电了,镍氢电池是会随着使用的电池电量减少的话,电池的电压也是跟着变化的,导致 ...

  8. Maven 本地仓库

    概述 Maven 的本地资源库是用来存储所有项目的依赖关系(插件 Jar 和其他文件,这些文件被 Maven 下载)到本地文件夹.很简单,当你建立一个 Maven 项目,所有相关文件将被存储在你的 M ...

  9. Java 字符串简介

    从概念上讲,Java 字符串就是 Unicode 字符序列.Java 没有内置的字符串类型,而是在标准 Java 类库中提供了一个预定义类,很自然地叫做 String.每个用双引号括起来的字符串都是 ...

  10. WPF combobox设置默认选项不生效的问题

    combobox 是常用的控件,当我们需要绑定设置默认选项时,往往会绑定 SelectedItem 属性去设置, 可是你会惊奇地发现SelectedItem的值绑定了, 它依旧是熟悉的模样 根据官方的 ...