ural 1989 subplindromes】的更多相关文章

https://vjudge.net/problem/URAL-1989 题意: 先给出一个字符串,对于这个字符串,有两种操作,一种是询问从下标x到y的串是不是回文串,另一种是将下标为pos的字符改为另一种字符. 思路: 哎,看题解补的,还好学会了如何用hash判断回文串以及线段树单点更新在hash中的应用. 下面来详细讲讲吧. 首先,对于一个字符串,一共出现过n个不同的字符,那么就可以把这个字符串用n+1进制表示(考虑特殊元素0,比如bbaa,如果用26进制的话,那么就是1100,就会跟bb0…
N - Subpalindromes URAL - 1989 这个是一个哈希+线段树,这个题目也不算特别难,但是呢,还比较有意思. 这个题目给你两个操作,一个是回答l~r 区间是不是回文,一个是对一个点进行单点修改. 这个用哈希还是比较好用的,首先就是把所有字符映射成一个数字,然后就相当于给你一串数字进行以上操作. 这个最好就是从小到大进行一个递增的哈希,这个看代码吧,说不太清楚. 主要注意一点就是最后要保证这个哈希的位数是一样的,具体看代码. #include<cstdio> #includ…
<题目链接> <转载于 >>>  > 题目大意:给你一段字符串,进行两种操作:1.询问[l,r]这个区间中的字符串是否是回文串: 2.更改该字符串中对应下标的字符. 解题分析: 快速判断字符串是不是回文串,可以用到多项式Hash.假设一个串s,那么字串s[i, j]的Hash值就是H[i, j]=s[i]+s[i+1]*x+s[i+2]*(x^2)+...+s[j]*(x^(j-i)).由于只有小写字母,因此x取27.但是H[i, j]这会很大,我们取模就可了,可…
Description You have a string and queries of two types: replace i'th character of the string by character a; check if substring sj...sk is a palindrome. Input The first line contains a string consisting of n small English letters. The second line con…
题意:给出一个字符串.有两种操作,一个是p a b,问字符串从位置a到位置b的子串是否是一个回文子串.还有一个操作 c a b,把字符串位置a的字符替换为b. 题解:由于字符串长度为1e5且问的次数也有1e5,所以暴力肯定是会超时的,然后考虑用树状数组维护字符串的hash值来解,两个操作分别用正反方向区间比对哈希值和单点改动. #include <cstdio> #include <cstring> #include <algorithm> #define ULL un…
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnlySuccess的博文“完全版线段树”里的大部分题目,其博文地址Here,然后也加入了自己做过的一些题目.整理时,更新了之前的代码风格,不过旧的代码仍然保留着. 同样分成四类,不好归到前四类的都分到了其他.树状数组能做,线段树都能做(如果是内存限制例外),所以也有些树状数组的题目,会标示出来,并且放…
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串中心位置,RMQ询问LCP = min (height[rank[l]+1] to height[rank[r]]),注意的是RMQ传入参数最好是后缀的位置,因为它们在树上的顺序未知,且左边还要+1. #include <cstdio> #include <algorithm> #in…
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and each orders a juice cocktail. It could be from 1 to 3 different juices in each cocktail. There are three juices in the bar: apple, banana and pineappl…
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best programmer in the world! Now he regularly takes part in various programming contests, attentively listens to problems analysis and upsolves problems. But…
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate integers together in their spare time. Nikolay thinks an integer is interesting if it is a prime number. However, Asya thinks an integer is interesting i…