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].
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.
Then for each query "2 i" output in single line one integer j.
1 aaabba aabbaa 7 2 0 2 1 2 2 2 3 1 1 2 b 2 0 2 3
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
int Init,a;
char str1[1000002],str2[1000002];
int min(int a,int b) { return a>b?b:a;}
struct segeTree
{
int left,right;
int first; //首次出现不匹配的位置
}Tree[1000002*4];
void build(int left,int right,int k)
{
if(left==right)
{
Tree[k].left=left;
Tree[k].right=right;
Tree[k].first=Init;
return ;
}
else
{
int mid=(left+right)/2;
Tree[k].left=left;
Tree[k].right=right;
Tree[k].first=Init;
build(left,mid,2*k);
build(mid+1,right,2*k+1);
}
}
void update(int x,int change,int k)
{
if(Tree[k].left==Tree[k].right&&Tree[k].left==x)
{
Tree[k].first=change;
return ;
}
int mid=(Tree[k].left+Tree[k].right)/2;
if(x<=mid)
update(x,change,2*k);
else if(x>mid)
update(x,change,2*k+1);
Tree[k].first=min(Tree[2*k].first,Tree[2*k+1].first);
}
int query(int index,int k)
{
if(index<=Tree[k].left)
return Tree[k].first;
int mid=(Tree[k].left+Tree[k].right)/2;
int d;
if(index<=mid)
a=query(index,2*k);
d=query(index,2*k+1);
return min(a,d);
}
int main()
{
int test,num,flag,index,ans,i,Count=0;
scanf("%d",&test);
while(test--)
{
Count++;
memset(str1,0,sizeof(str1));
memset(str2,0,sizeof(str2));
memset(Tree,0,sizeof(Tree));
scanf("%s%s",str1,str2);
int m=min(strlen(str1),strlen(str2));
Init=m+1;
build(1,m,1);
a=Init;
for(i=0;i<m;++i)
{
if(str1[i]==str2[i]) update(i+1,Init,1);
else if(str1[i]!=str2[i]) update(i+1,i+1,1);
}
scanf("%d",&num);
printf("Case %d:\n",Count);
while(num--)
{
scanf("%d",&flag);
if(flag==2)
{
scanf("%d",&index);
a=Init;
ans=query(index+1,1)-(index+1); //出现的位置减去自身的位置即可得出个数
printf("%d\n",ans);
}
if(flag==1)
{
int x,y;
char z;
scanf("%d%d",&x,&y);
cin>>z;
if(x==1)
{
if(str1[y]==str2[y]&&str2[y]!=z) update(y+1,y+1,1); //原先相等且替换之后不相等
if(str1[y]!=str2[y]&&str2[y]==z) update(y+1,Init,1); //原先不等但替换之后相等
str1[y]=z;
}
if(x==2)
{
if(str2[y]==str1[y]&&str1[y]!=z) update(y+1,y+1,1); //同上
if(str2[y]!=str1[y]&&str1[y]==z) update(y+1,Init,1);
str2[y]=z;
}
}
}
}
}