什么都不想说了。。。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 1000010
//#define MIN(a,b) (a>b?b:a)//以后还是老老实实的写函数吧,表示被它坑了一上午。。。
using namespace std;
int len;
int MIN(int A,int B)
{
return A<B?A:B;
}
struct node{
int left,right,mid,val;
}tree[N<<2];
void build(int num,int s,int e)
{
tree[num].left=s;
tree[num].right=e;
tree[num].val=len+1;
// cout<<"tree["<<num<<"].left"<<tree[num].left<<tree[num].right<<endl;
if(s<e)
{
tree[num].mid=(s+e)>>1;
build(num<<1,s,tree[num].mid);
build(num<<1|1,tree[num].mid+1,e);
}
}
void change(int s,int pos,int va)
{
if(tree[s].left==tree[s].right)
{
tree[s].val=va;
// cout<<"tree["<<s<<"].acount"<<tree[s].val<<endl;
return ;
}
if(pos<=tree[s].mid)
change(s<<1,pos,va);
else change(s<<1|1,pos,va);
tree[s].val=MIN(tree[s<<1].val,tree[s<<1|1].val);
}
int finds(int num,int s,int e)
{
if(s<=tree[num].left&&tree[num].right<=e)
{
// cout<<"tree["<<s<<"].acount"<<tree[s].val<<endl;
return tree[num].val;
}
if(e<=tree[num].mid)
return finds(num<<1,s,e);
else if(s>tree[num].mid)
return finds(num<<1|1,s,e);
else {
return MIN(finds(num<<1,s,tree[num].mid),finds(num<<1|1,tree[num].mid+1,e));
}
}
int main()
{
char s[2][1000010],c;
int T,Q,a,b,d;
scanf("%d",&T);
int k=1;
while(T--)
{
scanf("%s",s[0]);
scanf("%s",s[1]);
len=MIN(strlen(s[0]),strlen(s[1]));
build(1,1,len);
for(int i=0;i<len;i++)
{
if(s[0][i]!=s[1][i]) //将不匹配的位标存入线段树里
change(1,i+1,i+1);
}
printf("Case %d:\n",k++);
scanf("%d",&Q);
while(Q--)
{
scanf("%d",&a);
if(a==2)
{
scanf("%d",&b);
if(b>=len)
printf("0\n");
else
printf("%d\n",finds(1,b+1,len)-b-1);
}
else
{
scanf("%d %d %c",&b,&d,&c);
if(d>=len) continue;
b--;
if(s[b][d]==s[b^1][d]&&s[b][d]!=c)
change(1,d+1,d+1);
if(s[b][d]!=s[b^1][d]&&s[b^1][d]==c)
change(1,d+1,len+1);
s[b][d]=c;
}
}
}
return 0;
}