Maintain a string of digits and plus or minus signs under range replacements, and evaluate the arithmetic value of any substring with the calculator's operator rules.
Hard8Segment treeStringMathNo attempts yetTime limit3sMemory limit256 MBSuchan uses a calculator that only adds and subtracts. It has the digit buttons 0 through 9, the operator buttons + and -, an = button that shows the result, and an AC button that returns the calculator to its initial state. There is no C button that clears only the number being typed.
Type an expression in order and press =, and the screen shows the result. The numbers have no range limit, and a number may start with 0. To keep a mistyped operator from spoiling the result, the calculator follows three rules.
For example, press -15+0035-+-3- in order and then =. The calculator evaluates 0−15+35−3 and shows 17. Press only - and then =: the expression becomes 0−, the final - is ignored, and the result is 0.
Without a C button, one wrong digit forces Suchan to press AC and type the whole expression again. To get rid of that, he decided to build the following data structure.
There is a string S of length N made only of 0 through 9, +, and -. For a string X and 1≤i≤j≤∣X∣, let X[i..j] be the substring formed by concatenating the i-th through j-th characters of X.
Implement a data structure that supports the two operations below.
AC, type S[a..b] into the calculator, press =, and report the value shown on the screen.The first line contains the length of the string, N (1≤N≤200000).
The second line contains the string S. Its length is N.
The third line contains the number of queries, Q (1≤Q≤300000).
Each of the next Q lines contains one operation. The formats are below.
1 a b T. Here a and b are integers with 1≤a≤b≤N, and T is a string of length b−a+1. The lengths of T over all replace operations sum to at most 200000.2 a b. Here a and b are integers with 1≤a≤b≤N. At least one evaluate operation is given.Every string in the input consists only of 0 through 9, +, and -.
For each evaluate operation, print the result modulo 109+7 on its own line. The remainder of an integer x modulo 109+7 is the value of r for which integers q and r satisfy x=q(109+7)+r and 0≤r<109+7.