HDU 4339 Query

Query

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 2595    Accepted Submission(s): 860

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

2012 Multi-University Training Contest 4

解题思路:用<set>保存字符不同的位置,修改的话直接改,查的话用lower_bound,注意要把字符串长度len也添加进去,这是为了避免字符串全部相等的情况

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#define Maxn 1000005
using namespace std;
char str1[Maxn],str2[Maxn];
int main()
{
    int t,ncase=1,q,a,c,b;
    char ch;
    set<int> s;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d",&t);
    while(t--)
    {
        s.clear();
        set<int>::iterator it;
        scanf("%s%s",str1,str2);
        scanf("%d",&q);
        int len=strlen(str1);
        for(int i=0;i<len;i++)
            if(str1[i]!=str2[i])
                s.insert(i);
        s.insert(len);
        printf("Case %d:\n",ncase++);
        while(q--)
        {
            scanf("%d",&a);
            if(a==1)
            {
                scanf("%d %d %c\n",&b,&c,&ch);
                if(b==1)
                    str1[c]=ch;
                else
                    str2[c]=ch;
                if(str1[c]!=str2[c])
                    s.insert(c);
                else
                {
                    if(s.find(c)!=s.end())
                        s.erase(c);
                }
            }
            else
            {
                scanf("%d",&b);
                it=s.lower_bound(b);
                printf("%d\n",*it-b);
            }
        }
    }
    return 0;
}
时间: 2024-11-05 16:21:46

HDU 4339 Query的相关文章

HDU 4339 线段树区间合并

Query Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2573    Accepted Submission(s): 851 Problem Description You are given two strings s1[0..l1], s2[0..l2] and Q - number of queries.Your task

hdu 4339 multiset 或 线段树

http://acm.hdu.edu.cn/showproblem.php?pid=4339 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 -

hdu 6191 Query on A Tree(dfs序+可持久化字典树)

题目链接:hdu 6191 Query on A Tree 题意: 给你一棵树,每个节点有一个值,现在有q个询问,每个询问 询问一个u x,问以u为根的子树中,找一个节点,使得这个节点的值与x异或的值最大,输出那个最大的值. 题解: dfs序和一棵可持久化字典树就搞定了. 1 #include<bits/stdc++.h> 2 #define mst(a,b) memset(a,b,sizeof(a)) 3 #define F(i,a,b) for(int i=a;i<=b;++i) 4

HDU 4010 Query on The Trees (动态树)(Link-Cut-Tree)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4010 题意; 先给你一棵树,有 \(4\) 种操作: 1.如果 \(x\) 和 \(y\) 不在同一棵树上则在\(x-y\)连边. 2.如果 \(x\) 和 \(y\) 在同一棵树上并且 \(x!=y\) 则把 \(x\) 换为树根并把 \(y\) 和 \(y\) 的父亲分离. 3.如果 \(x\) 和 \(y\) 在同一棵树上则 \(x\) 到 \(y\) 的路径上所有的点权值\(+w\). 4

[hdu 6191] Query on A Tree

Query on A Tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 733    Accepted Submission(s): 275 Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey

hdu 4010 Query on The Trees(动态树)

题意:给定一幅图的连接情况,给出每个点的权值,四种操作: 1 x y 连接x.y所在子树: 2 x y 将同一棵树上的x,y分离,形成两棵子树: 3 w x y 将x.y之间路径上的所有点权加w: 4 x y 查询x.y路径上点权的最大值: 动态树学习参考:http://www.cnblogs.com/BLADEVIL/p/3510997.html http://wenku.baidu.com/view/75906f160b4e767f5acfcedb http://m.blog.csdn.ne

HDU 4010.Query on The Trees 解题报告

题意: 给出一颗树,有4种操作: 1.如果x和y不在同一棵树上则在xy连边 2.如果x和y在同一棵树上并且x!=y则把x换为树根并把y和y的父亲分离 3.如果x和y在同一棵树上则x到y的路径上所有的点权值+w 4.如果x和y在同一棵树上则输出x到y路径上的最大值 动态树入门题: #include <iostream> #include <cstdio> using namespace std; const int MAXN = 333333; struct node { int v

HDU 4010 Query on The Trees(动态树)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4010 题意:一棵树,四种操作: (1)若x和y不在一棵树上,将x和y连边: (2)若x和y在一棵树上,将x变成树根,将y从x树上分离: (3)若x和y在一棵树上,将x到y路径上的所有值增加det: (4)若x和y在一棵树上,输出x到y路径上的最大值. 思路:1操作用link维护,2操作用cut,34操作先split(x,y),然后对y做tag,并且记录路径的max值. 1 #include<iost

HDU 4339 (线段树字符标记)

题意:两字符串s1,s2,给定若干查询. 查询操作: 1 a b c 把第a个字符串的第b个字符换成字符c 2 a   查询从第a个字符开始s1[k]==s2[k],的个数.例如 aaa aab 查询 2 0 结果是2 思路:线段树的叶子值设为出现不同的位置i+1,初始为len+1:没次查询区间最小值,即最先不同的位置: #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio&g