Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 531 Accepted Submission(s): 164
AC代码:
#include <stdio.h>
#include <string.h>
char str[8][1000600];
int c[1000600];
int mx;
int lowbit( int x)
{
return x&(-x);
}
void updata( int x,int p)
{
while(x<=mx)
{
c[x]+=p;
x+=lowbit(x);
}
}
int sum( int x)
{
int s=0;
while(x>0)
{
s+=c[x];
x-=lowbit(x);
}
return s;
}
int main( )
{
int test,i,q,cnt;
int x,y,z,f,a;
char s[34];
scanf("%d",&test);
cnt=0;
while(test--)
{
memset(str,0,sizeof(str));
memset(c,0,sizeof(c));
scanf("%s",str[0]);
scanf("%s",str[1]);
for( mx=0;str[0][mx]&&str[1][mx];mx++);
for( i=0;i<mx;i++)
{
if(str[0][i]==str[1][i]) updata(i+1,1);
}
scanf("%d",&q);
printf("Case %d:\n",++cnt);
while(q--)
{
scanf("%d",&f);
if(f==2)
{
scanf("%d",&a);
++a;
int l=a,r=mx;
int mid;
while(l<=r)
{
mid=(l+r)>>1;
int k=sum(mid)-sum(a-1);
if(k>=mid-a+1) l=mid+1;
else r=mid-1;
}
printf("%d\n",r-a+1);
}
if(f==1)
{
scanf("%d%d%s",&x,&y,s);
x--;
char ch1=str[x^1][y],ch2=str[x][y];
str[x][y]=s[0];
if(ch1!=ch2&&ch1==s[0]) updata(y+1,1);
else if(ch1==ch2&&ch1!=s[0]) updata(y+1,-1);
}
}
}
return 0;
}