hdu4339query

Query
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3188 Accepted Submission(s): 1037

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

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = 1000007;
int flag[maxn<<2],sum[maxn<<2],t,cas = 1;
char s1[maxn],s2[maxn];
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
void push(int rt)
{
    sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}

void build(int l,int r,int rt)
{
    if(l == r)
    {
        if(s1[l] == s2[l]) flag[l] = 1;
        else flag[l] = 0;
        sum[rt] = flag[l];
        return ;
    }
    int m = (l+r)>>1;
    build(lson);
    build(rson);
    push(rt);
}

void update(int op,int pos,char c,int l,int r,int rt)
{
    if(l == r)
    {
        if(op == 1) s1[l] = c;
        if(op == 2) s2[l] = c;
        if(s1[l] == s2[l]) flag [l] = 1;
        else flag[l] = 0;
        sum[rt] = flag[l];
        return ;
    }
    int m = (l+r)>>1;
    if(pos<=m) update(op,pos,c,lson);
    else update(op,pos,c,rson);
    push(rt);
}

int query(int pre,int l,int r,int rt)
{
    if(l==r)return sum[rt];
    if(l<=pre&&pre<=r)
    {
        if(sum[rt]==r-l+1)
        return r-pre+1;
        else
        {
            int m=(l+r)>>1;
            int cat=0;
            if(pre<=m)
            {
                cat+=query(pre,lson);
                if(cat==m-pre+1)
                cat+=query(m+1,rson);
            }
            else
            cat+=query(pre,rson);
            return cat;
        }
    }
}

int main()
{
    int t;
    while(scanf("%d",&t)!=EOF)
    {
        scanf("%s%s",s1+1,s2+1);
        int len1=strlen(s1+1);
        int len2=strlen(s2+1);
        int len=max(len1,len2);
        build(1,len,1);
        int m,num,pre,idx;
        char c[2];
        scanf("%d",&m);
        printf("Case %d:\n",cas++);
        while(m--)
        {
            scanf("%d",&num);
            if(num==2)
            {
                scanf("%d",&pre);
                printf("%d\n",query(pre+1,1,len,1));
            }
            else
            {
                scanf("%d%d%s",&idx,&pre,&c);
                update(idx,pre+1,c[0],1,len,1);
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值