A Plus B Problem
Time limit3sMemory limit1024 MB
After each single-digit change to the first or second row, report the requested digit of the sum's last n digits and how many digits of the machine change.
- Level
Medium7 of 10
- Topics
- Segment tree, Math, Implementation
- Solved
- No attempts yet
Problem
JB got a machine that solves the A Plus B Problem, and he wants to know how it works. He heard that you are proficient in competitive programming and have learned many advanced data structures and algorithms, such as Link-Cut tree, Lagrange Inversion formula, Sweepline Mo, and so on. So he asks you to implement a program that solves the A Plus B Problem the same way the machine does.
The machine consists of digits. The digits of the first two rows can be changed arbitrarily, and the third row always equals the decimal sum of the first two rows. The third row keeps only the lowest digits, even if the sum has more than digits.
For example, when , the three rows can be 01234, 56789, 58023 or 56789, 58023, 14812.
To test your function, you are given queries. In the -th query, the -th digit of the -th row is changed to (the digit may stay the same). JB has no time to check your answers, so he only asks you to find the -th digit of the third row after the query and how many digits of the machine change in that query.
Input
The first line contains two integers and ().
The second line contains a string of digits, representing the first row of the machine.
The third line contains a string of digits, representing the second row of the machine.
The next lines follow. The -th of them contains three integers , , and (, , ).
Output
Output lines. In the -th line, output two integers: the -th digit of the third row after the query, and how many digits of the machine change in the query.
Hint
In the example, the initial rows are 01234, 56789, 58023.
After the 1st query, the rows are 01234, 06789, 08023.
After the 2nd query, the rows are 01234, 01789, 03023.
After the 3rd query, the rows are 01234, 01289, 02523.
After the 4th query, the rows are 01234, 01239, 02473.
After the 5th query, the rows are 01234, 01234, 02468.