I am happy
Time limit3sMemory limit512 MB
Given a digit string, apply range digit replacements and answer range queries for the number modulo 998244353.
- Level
Medium6 of 10
- Topics
- Segment tree, Math
- Solved
- No attempts yet
Problem
Aint-da, a passionate fan of the Korean professional baseball team Eagles, hopes that the Eagles will play in this year's postseason. If they do, he will finally break the 10-digit password.
In Korean professional baseball, a password is a string that lists a team's yearly ranks. Teams that have not reached the postseason for a long time become the butt of jokes because of their passwords. The Eagles' password is 5886899678. Other famous passwords include 6668587667 for the Twins and 8888577 for the Giants. The league has 10 teams, so ranks run from 1st to 10th. A year in which a team finished 10th is written as 0 in the password.
The Eagles currently have a 10-digit password, but it is not hard to imagine a future where their password has 1,000,000 digits. In the future, Aint-da has freed himself from all worldly attachments and gained a special ability. He can use this ability to change every game result from a period in which the Eagles finished in rank into a rank result. If the ranks look too unnatural, fans of other teams may become suspicious. So between uses of the ability, he checks how natural the password looks over a given period, using his own method.
Given the Eagles' future password and the sequence of operations Aint-da performs on it, write a program that carries out these operations on the password.
Input
The first line contains the string , the Eagles' password. consists only of digits, and its length is at least 1 and at most .
The second line contains the integer (1 ≤ ≤ 100,000), the number of actions Aint-da takes on the password.
From the third line on, each of the lines contains one action in the following form. There are two types.
1 i j from to(1 ≤ i ≤ j ≤ |S|, from and to are digits): Replace every digit equal to from in positions i through j with to.2 i j(1 ≤ i ≤ j ≤ |S|): Read the digits in positions i through j as one integer, and output its remainder when divided by 998,244,353.
At least one action of the second type is guaranteed.
Output
For each action of the second type, print the result on its own line, in the order the actions appear.
Hints
- Query 1: The integers in the range [6, 9] of the input are 9967, so print 9967.
- Query 2: Replace the 8s in the range [2, 9] with 5, which gives 5556599678.
- Query 3: Replace the 5s in the range [1, 3] with 0, which gives 0006599678.
- Query 4: Print 659, the integer formed by the range [1, 6].
- Query 5: Replace the 0s in the range [1, 10] with 2, which gives 2226599678.
- Query 6: Replace the 8s in the range [5, 8] with 1. This range has no 8, so nothing changes.
- Query 7: The integer formed by the range [1, 10] is 2,226,599,678. Its remainder modulo 998,244,353 is 230,110,972, so print that.