Password decryption
Time limit2sMemory limit256 MB
Count the ways an encrypted digit string can be split into trinomial values for digits 0-9, reporting the count after each point update.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Segment tree, Matrix, Implementation
- Solved
- No attempts yet
Problem
They changed the security system again. So we have to break into the bank system from scratch! We managed to intercept the password in encrypted form. We also have a person inside the bank who told us how passwords are encrypted in the new system.
The system password is a sequence of digits. It is encrypted as follows: instead of each digit, we write the value of a known quadratic trinomial evaluated at that digit. That is, instead of the digit we write the number , and the numbers for different digits are written consecutively without spaces. For example, if the encrypting trinomial is and the password being encrypted is 132, then after encryption we get 401; for instance, the password 198 is encrypted to 43625.
However, an encrypted password is not always decrypted uniquely. For example, consider the same trinomial and the encrypted password 401. It could result from encrypting four different passwords: 132, 134, 532, 534.
Moreover, we might have intercepted the encrypted password with some errors due to channel problems. There is a list of corrections that must be applied to the password in sequence. Each correction says to replace the digit at some position in the encrypted password with a given digit.
Since you are the chief hacker on the team, your task is to count the number of ways to decrypt the password. The number of ways must be output for the original password and after each correction operation. The answers can be quite large, so you need to find them modulo .
Input
The first line contains three integers , , and (, ), the coefficients of the trinomial. The second line contains a single string , the encrypted password, whose length does not exceed . The third line contains a single integer (), the number of corrections. The following lines each contain two numbers and ( the length of the string , ), the position at which to replace the digit and the new digit value.
It is guaranteed that the trinomial does not take negative values when substituting values from 0 to 9 for .
Output
Output numbers: the first number must be the number of ways to decrypt the original password, followed by the number of ways to decrypt the password after each correction. All numbers in the answer must be taken modulo .