Problem Aaccepts:1551submissions:11043Time limit:2000/1000 MS (java/others)Memory limit:65536/65536 K (java/others)Problem Description
The bear has a dictionary that stores a large number of words, and once, he makes all the words a long, long string. Now that the trouble has come, he forgets what the original string is, and what is magical is that he remembers the hash of the original string. The hash value of a string, calculated by the following formula:
H (s) =∏i=1i≤len (s) (si−28) (mod 9973) H (s) =\prod_{i=1}^{i\leq Len (s)} (s_{i}-28) \ (mod\ 9973)H(S)=∏?I=1?I≤LEN(S ?? (s? i ?? −28) (mod< Span class= "Mord mspace" > 9973< Span class= "Mclose")
Sis_{i}S? I?? The ASCII code that represents the S[i] character.
Please help the bear calculates the number of hashes in any segment of a large string.
Input
Multiple sets of test data, each set of test data the first line is a positive integernnn, representing the number of queries, a string on the second line, representing the large string in the title, followed by nnn rows with two positive integers per line aaa and bb< Span class= "katex-html" >< Span class= "Mord mathit" >b, which represents the starting position of the query and the ending position.
1≤n≤1,0001\leq n\leq 1,000 1< Span class= "Mrel" >≤n≤1,< Span class= "Mord" >000
1≤len (String) ≤100,0001\leq len (string) \leq 100,000 1≤len (string) ≤< Span class= "Mord" >100,0 00
1≤a,b≤len (String) 1\leq A,b\leq len (string)1≤a,b≤len (sTrIng)
Output
For each query, output an integer value that represents the hash value of the large string from the AA-a bit to the substring of the BB b-bit.
Sample InputCopy
2acmlove20151 118 101testmessage1 1
Sample OutputCopy
6891924088
Test instructions: give you a string to find an arbitrary interval of H (s) =∏i=1i≤len (s) (si−28) (mod 9973) ASCII code multiply mod 9973
Puzzle: Record prefix by the time of the use of inverse element I use the cost of horse small to seek inverse
1#include <iostream>2#include <cstring>3#include <cstdio>4 #definell __int645 #defineMoD 99736 using namespacestd;7 intN;8 Chara[100005];9ll gg[100005];Tenll sum=1; One intL,r; A ll Quickmod (ll A,ll b) - { -ll sum=1; the while(b) - { - if(b&1) -sum= (sum*a)%MoD; +b>>=1; -A= (a*a)%MoD; + } A returnsum; at } - intMain () - { - while(SCANF ("%d", &n)! =EOF) - { -Memset (A,0,sizeof(a)); inscanf"%s", a); - intlen=strlen (a); togg[0]=1; +sum=1; - for(intI=0; i<len;i++) the { *Sum= (sum* (a[i]- -))%MoD; $gg[i+1]=sum%MoD;Panax Notoginseng } - for(intI=1; i<=n;i++) the { +scanf"%d%d",&l,&R); All Ggg=quickmod (gg[l-1],mod-2); theprintf"%i64d\n", (GG[R]*GGG)%MoD); + } - } $ return 0; $}
2016 "Baidu Star"-Qualifying race (Astar Round1) A