Query
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2403 Accepted Submission(s): 812
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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#define INF 99999999
typedef long long LL;
using namespace std;
const int MAX=1000000+10;
int q,size;
int c[MAX];
char s[2][MAX];
int lowbit(int x){
return x&(-x);
}
void Update(int x,int d){
while(x<MAX){
c[x]+=d;
x+=lowbit(x);
}
}
int Query(int x){
int sum=0;
while(x>0){
sum+=c[x];
x-=lowbit(x);
}
return sum;
}
int search(int left,int right){
int l=left,ans=Query(left-1);
while(left<=right){
int mid=left+right>>1;
int sum=Query(mid)-ans;
if((mid-l+1)*2 == sum)left=mid+1;
else right=mid-1;
}
return left-l;//right-l+1
}
int main(){
int t,x,y,op,num=0;
char ch[3];
scanf("%d",&t);
while(t--){
memset(c,0,sizeof c);
scanf("%s%s",s[0],s[1]);
size=0;
while(s[0][size] && s[1][size]){
Update(size+1,1);
if(s[0][size] == s[1][size])Update(size+1,1);
++size;
}
scanf("%d",&q);
printf("Case %d:\n",++num);
for(int i=0;i<q;++i){
scanf("%d",&op);
if(op == 1){
scanf("%d%d%s",&x,&y,ch);
--x;
if(s[x][y] != s[x^1][y] && ch[0] == s[x^1][y])Update(y+1,1);
if(s[x][y] == s[x^1][y] && ch[0] != s[x][y])Update(y+1,-1);
s[x][y]=ch[0];
}else{
scanf("%d",&y);
printf("%d\n",search(y+1,size));
}
}
}
return 0;
}