# AC dreamoj 1011 Tree Array +hash maintain the prefix of the string and

Source: Internet
Author: User

http://acdream.info/problem?pid=1019

Problem Description

We have a long long string, and we'll have the kinds of operation on it.

C i y : Change the ith letter to y.
Q i j : Check whether the substring from ith to jth letter is a palindrome.

Input

There is multiple test cases.

The first line contains a string whose length was not large than 1,000,000.

The next line contains a integer N indicating the number of operations.

The next N lines Each lines contains a operation.

All letters in the input is lower-case.

Outputfor each query operation, output " Yes"If the corresponding substring is a palindrome, otherwise output" No". Sample Input
`aaaaa4q 1 5C 2 BQ 1 5Q 1 3`
Sample Output
`Yesnoyes`
`/**acdreamoj 1019 Tree Array +hash maintain the prefix and title of the string: Given a string, a single point of update, interval query whether the interval is a palindrome string. Problem-solving ideas: Hash is x1 * p^1+ x2*p^2 +x3*p^3 ... you can maintain prefixes and maintain two strings in a tree-like array, one is a positive string, and the other is crossdress for comparison. The hash value of the string interval s[l~r] is sum (s[r]-s[l-1])/hash[l-1];*/#include <stdio.h> #include <string.h> #include < Iostream> #include <algorithm>using namespace std;typedef unsigned long long ll;const int Maxn=1000010;const int seed=13;    LL Hash[maxn],c[2][maxn];char s[maxn];int len;void init () {hash[0]=1; for (int i=1;i<maxn;i++) hash[i]=hash[i-1]*seed;} int lowbit (int x) {return x& (-X);}        void Add (int i,int x,ll POS) {while (X<=len) {c[i][x]+=pos;    X+=lowbit (x);    }}ll sum (int i,int x) {LL ans=0;        while (x) {ans+=c[i][x];    X-=lowbit (x); } return ans; LL gethash (int i,int l,int r) {return sum (i,r)-sum (I,L-1);}     int main () {init ();         while (~SCANF ("%s", s+1)) {memset (c,0,sizeof (C));         Len=strlen (s+1);   for (int i=1;i<=len;i++)      {Add (0,i, (s[i]-' a ') *hash[i]);         Add (1,len+1-i, (s[i]-' a ') *hash[len+1-i]);         } int T;         Cin >> T;             while (t--) {char c[5];             scanf ("%s", c);                 if (c[0]== ' C ') {char b[5];                 int A;                 scanf ("%d%s", &a,b);                 Add (0,a, (B[0]-s[a]) *hash[a]);                 Add (1,len+1-a, (B[0]-s[a]) *hash[len+1-a]);             S[A]=B[0];                 } else {int l,r;                 scanf ("%d%d", &l,&r);                 if (Gethash (0,l,r) *hash[len-r]==gethash (1,len+1-r,len+1-l) *HASH[L-1])//use cross multiplication to replace the multiply puts ("yes");             Else puts ("no"); }}} return 0;}`

AC dreamoj 1011 Tree Array +hash maintain the prefix of the string and

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.