hdu 4339 Query

Query

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 531    Accepted Submission(s): 164


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
 

 

Source
 

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;
}

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4339

posted @ 2012-08-03 11:21  jiai  Views(176)  Comments(0Edit  收藏  举报