Maggie's Homework
Time limit4sMemory limit1024 MB
Range-assign updates overwrite digits, and each query asks for the sum of all substring values in a range that do not start with 0, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Segment tree, Math, String
- Solved
- No attempts yet
Statement
Maggie Simpson has finally started first grade after thirty seasons. For handwriting practice, the teacher asked the children to write N digits from 0 to 9 in a row, in any order.
After hours of effort, Maggie finished the homework and ran off to play with her friends, leaving the paper on the desk. Lisa Simpson walked into the room and noticed the notebook.
Lisa quickly found the sum of all the digits Maggie wrote. Then Bart came in with a harder task: perform M operations on this digit string. Positions are numbered from 1 to N, left to right. There are two types of operations.
1 : replace every digit at positions through with the digit .
2 : compute the sum of all numbers whose decimal representations occur as substrings of the segment from position through . Each number is counted as many times as its representation occurs in the segment. Substrings that begin with '0' are not included in the sum. Output the answer modulo .
Input
The first line contains two integers N and M separated by a space, the number of digits and the number of Bart's operations ().
The second line contains N digits from 0 to 9, separated by spaces.
Each of the next M lines describes an operation. A line 1 is a first-type operation with and . A line 2 is a second-type operation with .
Output
For each operation of the second type, print the answer modulo on its own line. If there are no operations of the second type, print nothing.
Note
In the first sample, the answer to the first type-2 operation is . The answer to the second is . That sum has fewer terms because 03 is not a valid decimal representation of an integer.