Codeforces Gym 100570 E. Palindrome Query Manacher
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的更多相关文章
- Codeforces Gym 100571A A. Cursed Query 离线
A. Cursed QueryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100571/problem ...
- Gym - 100570E:Palindrome Query (hash+BIT+二分维护回文串长度)
题意:给定字符串char[],以及Q个操作,操作有三种: 1:pos,chr:把pos位置的字符改为chr 2:pos:问以pos为中心的回文串长度为多长. 3:pos:问以pos,pos+1为中心的 ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- 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 ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
随机推荐
- ASP.NET MVC+Bootstrap个人博客之后台dataTable数据列表(五)
jQuery dataTables 插件是一个优秀的表格插件,是后台工程师的福音!它提供了针对数据表格的排序.浏览器分页.服务器分页.查询.格式化等功能.dataTables 官网也提供了大量的演示 ...
- UI篇--android实现底部按钮布局
1.采用LinearLayout布局: <LinearLayout android:id="@+id/main" android:layout_width="fil ...
- 擦亮自己的眼睛去看SQLServer之简单Select(转)
摘要:这篇文章主要和大家讨论几乎所有人都熟悉,但不少人又陌生的一条select语句. 这篇文章主要和大家讨论几乎所有人都熟悉,但不少人又陌生的一条select语句.不知道大家有没有想过到底是什么东西让 ...
- 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(1)
我们要做的第一件事是安装ElasticSearch.对于多数应用程序,您开始安装和配置,通常忘记这些步骤的重要性,直到发生了糟糕的事情.这章我们将广泛关注ElasticSearch的这部分.请注意本章 ...
- 《Python CookBook2》 第一章 文本 - 替换字符串中的子串
替换字符串中的子串 任务: 给定一个字符串,通过查询一个字符串替换字典,将字符串中被标记的子字符串替换掉. 解决方案: >>> import string >>> ...
- memcpy、memmove、memset及strcpy函数实现和理解
memcpy.memmove.memset及strcpy函数实现和理解 关于memcpy memcpy是C和C++ 中的内存拷贝函数,在C中所需的头文件是#include<string.h> ...
- LeetCode题解——String to Integer(atoi)
题目: 字符串转换为数字. 解法: 这道题的意思是要考虑到,如果有前置的空字符,则跳过:如果超出数字范围,则返回最大/最小整数:如果碰到第一个不能转换的字符,则返回. 代码: class Soluti ...
- HTML 5:绘制旋转的太极图
HTML: <!DOCTYPE> <html> <head> <meta charset="utf-8" /> <title& ...
- Python对象初探
数据结构 PyObject_HEAD //对象公共头部 Py_ssize_t ob_refcnt; //对象引用数 PyTypeObject *ob_type; //对象类型 PyObject_V ...
- [Hive - LanguageManual] Hive Default Authorization - Legacy Mode
Disclaimer Prerequisites Users, Groups, and Roles Names of Users and Roles Creating/Dropping/Using R ...