Codeforces Round #423 (Div. 2, rated, based on VK Cup finals) E. DNA Evolution tree Array

Source: Internet
Author: User

E. DNA evolutiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

Everyone knows that DNA strands consist of nucleotides. There is four types of nucleotides: "A", "T", "G", "C". A DNA strand is a sequence of nucleotides. Scientists decided to track evolution of a rare species, which DNA strand was string s initially.

Evolution of the species is described as a sequence of changes in the DNA. Every change was a change of some nucleotide, for example, the following change can happen in DNA strand "aagc": The SE Cond nucleotide can change to "T" so, the resulting DNA strand is "atgc".

Scientists know that some segments of the DNA strand can is affected by some unknown infections. They can represent an infection as a sequence of nucleotides. Scientists is interested if there is any changes caused by some infections. Thus They sometimes want to know the value of impact of some infection to some segment of the DNA. This value is computed as follows:

    • Let the infection is represented as a string  e , and let scientists be inter ested in DNA strand segment starting from Position  l  to Position  R , inclusive.
    • Prefix of the String  eee ...  (i.e. the string that consists of infinitely Many repeats of String  e ) is written under the string  s  from position  l to position < Span class= "Tex-span" > R , inclusive.
    • the value of impact is the number of positions where letter of String  s  coin Cided with the letter written under it.

Being A developer, Innokenty is interested in bioinformatics also, so the scientists asked him for help. Innokenty is busy preparing VK cups, so he decided to delegate the problem to the competitors. Help the Scientists!

Input

The first line contains the string s (1≤|  S| ≤105) that describes the initial DNA strand. It consists only by capital 中文版 letters "A", "T", "G" and "C".

The next line contains a single integer q (1≤ q ≤105)-the number of events.

After the, Q Lines follow, each describes one event. Each of the lines have one of the formats:

  • 1 x C, where x is an integer (1≤ x ≤| S|), and C are a letter "a", "T", "G" or "C", which means that there are a change in T He dna:the nucleotide at position x was now C.
  • 2 L r E, where l, R is integers (1≤ lr ≤| S|), and e is a string of letters "a", "T", "G" and "C" (1≤|  E| ≤10), which means that scientists is interested in the value of impact of infection e to the segment of DNA strand from position L to position R, inclusive.
Output

For each scientists ' query (second type query) print a single integer in a new line-the value of impact of the infection On the DNA.

Examplesinput
Atgcatgc
4
2 1 8 ATGC
2 2 6 TTT
1 4 T
2 2 6 TA
Output
8
2
4
Input
Gagttgttaa
6
2 3 4 TATGGTG
1 1 T
1 6 G
2 5 9 Agtaata
1 G
2 2 6 TTGT
Output
0
3
1
Note

Consider the first example. In the first query of second type all characters coincide, so the answer is 8. In the second query we compare string "ttttt ..." and the substring "tgcat". There is and matches. In the third query, after the DNA change, we compare string "tatat ..." ' with substring ' tgtat '. There is 4 matches.

Test instructions: give you a string of only ATCG four characters

Q Operation,

1 operation, change x position to character C

2 operation, to find the interval [l,r] to match e,e has been circulating, to find all the number of matches;

Idea: Array of arrays, note that the length of E is [1,10];

The loop section representing the beginning of the length I with J is the position mark of the I character C, see Code;

#pragmaComment (linker, "/stack:1024000000,1024000000")#include<iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>using namespacestd;#defineLL Long Long#definePi (4*atan (1.0))#defineEPS 1e-14#defineBug (x) cout<< "Bug" <<x<<endl;Const intn=1e5+Ten, m=2e6+Ten, inf=1e9+Ten;ConstLL inf=1e18+Ten, mod=1e9+7;structayt{intTree[n]; intLowbit (intx) {returnx&-x; }    voidUpdateintXintc) { while(x<N) {tree[x]+=C; X+=lowbit (x); }    }    intQueryintx) {intans=0;  while(x) {ans+=Tree[x]; X-=lowbit (x); }        returnans; }}; AYT tree[ One][ One][4];//A loop section representing the starting point of the length I with J is the position mark of the I character CintgcChara) {    if(a=='A')return 0; if(a=='T')return 1; if(a=='C')return 2; return 3;}Chara[n],ch[Ten]="ATCG";intMain () {scanf ("%s", A +1); intN=strlen (A +1);  for(intI=1; i<=Ten; i++)    {         for(intj=1; j<=i; J + +)        {             for(intk=0; k<4; k++)            {                 for(intL=j; l<=n; l+=i)if(ch[k]==A[l]) tree[i][j][k].update (L,1); }        }    }    intQ; scanf ("%d",&q);  while(q--)    {        intT; scanf ("%d",&t); if(t==1)        {            intx; Charf[2]; scanf ("%d%s",&x,f); if(a[x]==f[0])Continue;  for(intI=1; i<=Ten; i++)            {                 for(intj=1; j<=i; J + +)                {                    if(x%i==j%i) for(intk=0; k<4; k++)                    {                        if(a[x]==Ch[k]) tree[i][j][k].update (x,-1); if(f[0]==Ch[k]) tree[i][j][k].update (x,1); }}} A[x]=f[0]; }        Else        {            intl,r,ans=0; Charf[ A]; scanf ("%d%d%s", &l,&r,f+1); intLen=strlen (f+1);  for(intI=1; i<=len; i++)            {                intx=GC (F[i]); intS= (l+i-1)%len? (l+i-1)%Len:len; Ans+=tree[len][s][x].query (R)-tree[len][s][x].query (l1); } printf ("%d\n", ans); }    }    return 0;}

Codeforces Round #423 (Div. 2, rated, based on VK Cup finals) E. DNA Evolution tree Array

Contact Us

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.