E. Palindrome Query
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100570/problem/E

Description

De Prezer loves palindrome strings. A string s1s2...sn is palindrome if and only if it is equal to its reverse.

De Prezer also loves queries.

You are given string s of length n and m queries. There are 3 types of queries :

1. 1 p x : Modify sp = x where 1 ≤ p ≤ n and x is a lower case English letter.

2. 2 p : Print the length of the largest palindrome substring of s like slsl + 1...sr such that l ≤ p ≤ r and r - p = p - l. (1 ≤ p ≤ n)

3. 3 p : Print the length of the largest palindrome substring of s like slsl + 1...sr such that l ≤ p and p + 1 ≤ r and r - p - 1 = p - l. (1 ≤ p ≤ n - 1) or  - 1 if there is no such substring.

Input

The first line of input contains s and m.

Next m lines contain queries.

1 ≤ n, m ≤ 105

s only contains lower case English letters.

Output

For each query of type 2 and 3 print the answer in a single line.

Sample Input

abcd 3
3 1
1 2 c
3 2

Sample Output

-1
2

HINT

题意

给你一个字符串,然后有3个操作

1.修改一个位置的字符为

2.查询以p为中心的奇数回文串最长长度

3.查询以p为中心的偶数回文串最长长度

题解

这道题看起来很唬人,其实暴力可过……

直接傻逼暴力就好

我拍的是manacher,直接暴力修改,也是直接过了……

代码

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 201001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//**************************************************************************************
char s[maxn];
char str[maxn];
int p[maxn];
int dp1[maxn];
int dp2[maxn];
int l;
void manacher(char s[],int l)
{
int i,j,k,ans=;
for(i=;i<=l;++i)str[i<<]=s[i],str[(i<<)+]='#';
str[]='#';str[l*+]='#';str[]='&';str[l*+]='$';
l=l*+;j=;
for(i=;i<=l;)
{
while(str[i-j-]==str[i+j+])++j;
p[i]=j;if(j>ans)ans=j;
for(k=;k<=j&&p[i]-k!=p[i-k];++k)p[i+k]=min(p[i-k],p[i]-k);
i+=k;j=max(j-k,);
}
}
struct node
{
int p;
char c;
};
vector<node> Q;
int main()
{
//test;
int m;
scanf("%s",s+);
scanf("%d",&m);
l=strlen(s+);
manacher(s,l);
l=l*+;
for(int ii=;ii<m;ii++)
{
int k;
scanf("%d",&k);
if(k==)
{
int pp;
pp=read();
char c;
scanf("%c",&c);
Q.push_back((node){pp,c});
}
if(k==)
{
if(Q.size())
{
for(int i=;i<Q.size();i++)
{
s[Q[i].p]=Q[i].c;
}
Q.clear();
manacher(s,l/);
}
int pp=read();
printf("%d\n",p[pp*]);
}
if(k==)
{
if(Q.size())
{
for(int i=;i<Q.size();i++)
{
s[Q[i].p]=Q[i].c;
}
Q.clear();
manacher(s,l/);
}
int pp=read();
if(p[pp*+]==)
printf("-1\n");
else
printf("%d\n",p[pp*+]);
}
}
}

Codeforces Gym 100570 E. Palindrome Query Manacher的更多相关文章

  1. Codeforces Gym 100571A A. Cursed Query 离线

    A. Cursed QueryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100571/problem ...

  2. Gym - 100570E:Palindrome Query (hash+BIT+二分维护回文串长度)

    题意:给定字符串char[],以及Q个操作,操作有三种: 1:pos,chr:把pos位置的字符改为chr 2:pos:问以pos为中心的回文串长度为多长. 3:pos:问以pos,pos+1为中心的 ...

  3. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  4. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  5. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  6. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  7. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  8. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...

  9. CodeForces Gym 100213F Counterfeit Money

    CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...

随机推荐

  1. 利用Modbus协议读取电能表的数据

    1.电脑要有485转232的转换器2.你要看懂DLT_645—1997规约的通讯协议,现在大多电能表厂都会遵行这个通讯协议,DLT_645—1997规约不是最新的通讯协议.就看电表的使用什么通讯协议. ...

  2. .NET之美——C#中的委托和事件(续)

    C#中的委托和事件(续) 引言 如果你看过了 C#中的委托和事件 一文,我想你对委托和事件已经有了一个基本的认识.但那些远不是委托和事件的全部内容,还有很多的地方没有涉及.本文将讨论委托和事件一些更为 ...

  3. oracle 统计语句 与常见函数的归纳(未完待续)

    一.统计语句 1. count count(*)与count(0)语句的区别: count(*)统计所有数量 count(0)统计第一列不为空的 2. 两个统计量的减法 select (select ...

  4. C#主线程等待子线程运行结束

    佐左佑右 原文 C#主线程等待子线程运行结束 由于主程序中调用matlab的dll文件进行计算要用较长的时间,主界面会有很长时间的卡顿,造成的用户感受十分不好,因此我想在调用时,将调用放入子线程中,然 ...

  5. XtraGrid的若干种用法 z

    支持多种类型的数据集合作为数据源 XtraGrid与传统的DataGridView一样,支持多种类型作为其数据源.下面例子是将DataTable, List<T>和数组分别绑定到XtraG ...

  6. C#发送Email邮件(实例:QQ邮箱和Gmail邮箱)

    下面用到的邮件账号和密码都不是真实的,需要测试就换成自己的邮件账号. 需要引用: using System.Net.Mail; using System.Text; using System.Net; ...

  7. Qt使用Cookies对网站操作之Get和POST

    1.添加QNetwork模块: a.Qt Creator中打开.pro文件添加QT+=Network; b.VS_Qt中项目属性中Qt Project Settings中Qmodules中勾选”QNe ...

  8. 告别where 1=1 最佳方案分享

    已经有2年没有用过where 1=1了,没想到换了家公司后,又让我看到了它.在网络上面搜索了一下,发现没有人提供一个比较好的方案来解决这一问题.很多人说可以让数据库的优化机制去处理,但是,我想对于大部 ...

  9. STL六大组件之——仿函数偷窥

    仿函数(functor),就是使一个类或类模板的使用看上去象一个函数.其实现就是类或类模板中对operator()进行重载,这个类或类模板就有了类似函数的行为.仿函数是智能型函数就好比智能指针的行为像 ...

  10. 大话细说ORM

    什么是ORM? ORM,即对象关系映射(Object Relational Mapping)表示一种技术,用来把(对象模型)表示的对象映射到基于SQL的(关系模型)数据结构中去. 说得通俗点,就是在对 ...