#P6553. Hymn String Query

    ID: 19766 Type: Default 1000ms 256MiB

Hymn String Query

Hymn String Query

A hymn string is a string that consists solely of the digits \(1\), \(4\), and \(5\). You are given such a string \(S\) and need to perform a series of operations on it. In each operation, you are given two integers \(l\) and \(r\) (1-indexed) along with a replacement string \(R\). Replace the substring from index \(l\) to \(r\) (inclusive) with \(R\). After each replacement, answer the following three queries on the entire string, taking all results modulo \(99824353\):

  1. The number of occurrences of the digit \(1\).
  2. The sum of all the digits in \(S\).
  3. The product of all the digits in \(S\).

Note that every arithmetic operation (summation or multiplication) should be performed modulo \(99824353\).

inputFormat

The first line contains a hymn string \(S\) consisting only of the characters \(1\), \(4\), and \(5\). The second line contains a positive integer \(Q\), the number of operations. Each of the following \(Q\) lines contains two integers \(l\) and \(r\) and a replacement string \(R\) separated by spaces. Note that \(l\) and \(r\) are 1-indexed. For each operation, replace the substring of \(S\) from index \(l\) to \(r\) with \(R\), and then answer the three queries as described above.

outputFormat

For each operation, output three space-separated integers on a new line corresponding to:

  1. The count of digit \(1\) in the current string.
  2. The sum of all digits in the current string taken modulo \(99824353\).
  3. The product of all digits in the current string taken modulo \(99824353\).

sample

145
1
1 2 41
1 10 20